From d8cb55b223b18f7c32ef1579b4e39abb0a536193 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Mon, 23 Jul 2007 21:26:03 +0000 Subject: [PATCH] Add simple gbfile based Palm/OS PDB support. Drop 'coldsync' and 'pilot-link'. --- Makefile.in | 59 +- cetus.c | 72 +- coldsync/Artistic | 131 --- coldsync/Makefile | 0 coldsync/Makefile.in | 0 coldsync/README | 211 ---- coldsync/README.gpsbabel | 10 - coldsync/cs-config.h | 8 - coldsync/palm.h | 55 - coldsync/pconn/util.h | 60 -- coldsync/pdb.c | 2038 ------------------------------------ coldsync/pdb.h | 273 ----- coldsync/util.c | 293 ------ configure | 642 ++++++++---- configure.in | 2 +- copilot.c | 83 +- coto.c | 120 +-- gcdb.c | 66 +- geoniche.c | 124 +-- gpilots.c | 67 +- gpspilot.c | 64 +- mag_pdb.c | 34 +- magnav.c | 67 +- mapopolis.c | 69 +- msvc/GPSBabel-msvc7.vcproj | 98 +- msvc/GPSBabel.dsp | 58 +- msvc/GPSBabel.vcproj | 122 +-- msvc/build.bat | 7 +- palmdoc.c | 71 +- pathaway.c | 118 +-- pdbfile.c | 411 ++++++++ pdbfile.h | 84 ++ pilot-link/README.gpsbabel | 6 - pilot-link/pi-args.h | 36 - pilot-link/pi-buffer.c | 118 --- pilot-link/pi-buffer.h | 143 --- pilot-link/pi-debug.h | 101 -- pilot-link/pi-dlp.h | 1856 -------------------------------- pilot-link/pi-error.h | 95 -- pilot-link/pi-file.c | 1534 --------------------------- pilot-link/pi-file.h | 435 -------- pilot-link/pi-macros.h | 290 ----- pilot-link/pi-source.h | 0 quovadis.c | 83 +- quovadis.h | 3 +- 45 files changed, 1344 insertions(+), 8873 deletions(-) delete mode 100644 coldsync/Artistic delete mode 100644 coldsync/Makefile delete mode 100644 coldsync/Makefile.in delete mode 100644 coldsync/README delete mode 100644 coldsync/README.gpsbabel delete mode 100644 coldsync/cs-config.h delete mode 100644 coldsync/palm.h delete mode 100644 coldsync/pconn/util.h delete mode 100644 coldsync/pdb.c delete mode 100644 coldsync/pdb.h delete mode 100644 coldsync/util.c create mode 100644 pdbfile.c create mode 100644 pdbfile.h delete mode 100644 pilot-link/README.gpsbabel delete mode 100644 pilot-link/pi-args.h delete mode 100644 pilot-link/pi-buffer.c delete mode 100644 pilot-link/pi-buffer.h delete mode 100644 pilot-link/pi-debug.h delete mode 100644 pilot-link/pi-dlp.h delete mode 100644 pilot-link/pi-error.h delete mode 100644 pilot-link/pi-file.c delete mode 100644 pilot-link/pi-file.h delete mode 100644 pilot-link/pi-macros.h delete mode 100644 pilot-link/pi-source.h diff --git a/Makefile.in b/Makefile.in index b62d8d666..4366b462e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -33,7 +33,7 @@ OUTPUT_SWITCH=-o # #OPTIMIZATION=-O $(EXTRA_OPTIMIZATION) #DEBUGGING=-g $(EXTRA_DEBUGGING) # add -DDEBUG_MEM to turn on memory allocation logging -GBCFLAGS=$(EXTRA_CFLAGS) $(DEBUGGING) -I. -I@srcdir@/coldsync \ +GBCFLAGS=$(EXTRA_CFLAGS) $(DEBUGGING) -I. \ $(OPTIMIZATION) @CFLAGS@ LDFLAGS=$(EXTRA_LDFLAGS) @LDFLAGS@ PREFIX=@prefix@ @@ -73,7 +73,7 @@ JEEPS=jeeps/gpsapp.o jeeps/gpscom.o \ # jeeps/gpsfmt.o jeeps/gpsinput.o jeeps/gpsproj.o -@PALM_DB_CMT@PALM_DB=coldsync/util.o coldsync/pdb.o # pilot-link/pi-file.o pilot-link/pi-buffer.o +@PALM_DB_CMT@PALM_DB=pdbfile.o SHAPE=shapelib/shpopen.o shapelib/dbfopen.o @@ -337,8 +337,7 @@ brauniger_iq.o: brauniger_iq.c defs.h config.h queue.h gbtypes.h \ cet.o: cet.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ gbfile.h cet.h cet_util.h inifile.h cetus.o: cetus.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ - zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h pdbfile.h cet_util.o: cet_util.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h cet/ansi_x3_4_1968.h \ cet/iso_8859_1.h cet/iso_8859_15.h cet/cp1252.h cet/iso_8859_2.h \ @@ -360,11 +359,9 @@ compegps.o: compegps.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h jeeps/gpsinput.h \ jeeps/gpsproj.h copilot.o: copilot.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ - zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h grtcirc.h + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h grtcirc.h pdbfile.h coto.o: coto.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ - gbfile.h cet.h cet_util.h inifile.h csv_util.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h grtcirc.h + gbfile.h cet.h cet_util.h inifile.h csv_util.h grtcirc.h pdbfile.h cst.o: cst.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ gbfile.h cet.h cet_util.h inifile.h strptime.h csv_util.o: csv_util.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ @@ -448,8 +445,7 @@ gbser_posix.o: gbser_posix.c defs.h config.h queue.h gbtypes.h \ gbser_private.h gbsleep.o: gbsleep.c config.h gcdb.o: gcdb.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ - gbfile.h cet.h cet_util.h inifile.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h + gbfile.h cet.h cet_util.h inifile.h pdbfile.h gdb.o: gdb.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ gbfile.h cet.h cet_util.h inifile.h csv_util.h garmin_fs.h jeeps/gps.h \ jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gps.h \ @@ -460,8 +456,8 @@ gdb.o: gdb.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ geo.o: geo.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ gbfile.h cet.h cet_util.h inifile.h xmlgeneric.h geoniche.o: geoniche.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ - zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h jeeps/gpsmath.h jeeps/gps.h \ + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h pdbfile.h \ + jeeps/gpsmath.h jeeps/gps.h \ jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h \ jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \ jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \ @@ -480,12 +476,10 @@ glogbook.o: glogbook.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ google.o: google.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h xmlgeneric.h gpilots.o: gpilots.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ - zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h garmin_tables.h + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h garmin_tables.h \ + pdbfile.h gpspilot.o: gpspilot.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ - zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h pilot-link/pi-file.h \ - pilot-link/pi-dlp.h pilot-link/pi-macros.h pilot-link/pi-args.h \ - pilot-link/pi-buffer.h pilot-link/pi-error.h + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h pdbfile.h gpssim.o: gpssim.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h gpsutil.o: gpsutil.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ @@ -538,11 +532,10 @@ maggeo.o: maggeo.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h xmlgeneric.h \ magellan.h magnav.o: magnav.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ - zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h pdbfile.h mag_pdb.o: mag_pdb.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ - zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h jeeps/gpsmath.h jeeps/gps.h \ + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h pdbfile.h \ + jeeps/gpsmath.h jeeps/gps.h \ jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h \ jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \ jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \ @@ -592,16 +585,13 @@ palmdoc.o: palmdoc.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h \ jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h \ jeeps/gpsmem.h jeeps/gpsrqst.h jeeps/gpsinput.h jeeps/gpsproj.h \ - coldsync/palm.h coldsync/../gbtypes.h coldsync/pdb.h + pdbfile.h pathaway.o: pathaway.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ - zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h coldsync/palm.h \ - coldsync/../gbtypes.h coldsync/pdb.h csv_util.h strptime.h + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h csv_util.h strptime.h \ + pdbfile.h pcx.o: pcx.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ gbfile.h cet.h cet_util.h inifile.h garmin_tables.h csv_util.h -pi-file.o: pilot-link/pi-file.c pilot-link/pi-debug.h \ - pilot-link/pi-args.h pilot-link/pi-source.h pilot-link/pi-file.h \ - pilot-link/pi-dlp.h pilot-link/pi-macros.h pilot-link/pi-buffer.h \ - pilot-link/pi-error.h +pdbfile.o: pdbfile.h pdbfile.c defs.h queue.h gbfile.h polygon.o: polygon.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h filterdefs.h position.o: position.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ @@ -613,7 +603,7 @@ psp.o: psp.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ queue.o: queue.c queue.h quovadis.o: quovadis.c quovadis.h defs.h config.h queue.h gbtypes.h \ zlib/zlib.h zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h \ - coldsync/palm.h coldsync/../gbtypes.h coldsync/pdb.h + pdbfile.h radius.o: radius.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h filterdefs.h grtcirc.h raymarine.o: raymarine.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ @@ -727,10 +717,6 @@ xmltag.o: xmltag.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h yahoo.o: yahoo.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h xmlgeneric.h -coldsync/pdb.o: coldsync/pdb.c config.h coldsync/cs-config.h \ - coldsync/palm.h coldsync/../gbtypes.h coldsync/pdb.h -coldsync/util.o: coldsync/util.c config.h coldsync/cs-config.h \ - coldsync/pconn/util.h coldsync/palm.h coldsync/../gbtypes.h jeeps/gpsapp.o: jeeps/gpsapp.c jeeps/gps.h jeeps/../defs.h \ jeeps/../config.h jeeps/../queue.h jeeps/../gbtypes.h \ jeeps/../zlib/zlib.h jeeps/../zlib/zconf.h jeeps/../gbfile.h \ @@ -868,13 +854,6 @@ jeeps/gpsutil.o: jeeps/gpsutil.c jeeps/gps.h jeeps/../defs.h \ jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h \ jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h \ jeeps/gpsinput.h jeeps/gpsproj.h -pilot-link/pi-buffer.o: pilot-link/pi-buffer.c defs.h config.h queue.h \ - gbtypes.h zlib/zlib.h zlib/zconf.h gbfile.h defs.h cet.h cet_util.h \ - inifile.h pilot-link/pi-buffer.h pilot-link/pi-args.h -pilot-link/pi-file.o: pilot-link/pi-file.c pilot-link/pi-debug.h \ - pilot-link/pi-args.h pilot-link/pi-source.h pilot-link/pi-file.h \ - pilot-link/pi-dlp.h pilot-link/pi-macros.h pilot-link/pi-buffer.h \ - pilot-link/pi-error.h shapelib/dbfopen.o: shapelib/dbfopen.c shapelib/shapefil.h config.h shapelib/shpopen.o: shapelib/shpopen.c shapelib/shapefil.h config.h zlib/adler32.o: zlib/adler32.c zlib/zlib.h zlib/zconf.h diff --git a/cetus.c b/cetus.c index 2406bdd71..8617a2995 100644 --- a/cetus.c +++ b/cetus.c @@ -30,9 +30,8 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" -# +#include "pdbfile.h" + #define MYNAME "Cetus" #define MYTYPE_WPT 0x43577074 /* CWpt */ #define MYTYPE_TRK 0x7374726d /* strm */ @@ -137,12 +136,10 @@ typedef struct cetus_track_point_s #define TRACK_POINT_SIZE sizeof(struct cetus_track_point_s) -static FILE *file_in; -static FILE *file_out; +static pdbfile *file_in, *file_out; static const char *out_fname; -static struct pdb *opdb; -static struct pdb_record *opdb_rec; static short_handle mkshort_wr_handle; +static int ct; static char *dbname = NULL; static char *appendicon = NULL; @@ -180,7 +177,7 @@ read_track_point(cetus_track_point_t *data, const time_t basetime) if (data->hdop != -1) wpt->hdop = (float) data->hdop / 10; i = be_read16(&data->speed); - if (i != 10000) WAYPT_SET(wpt, speed, ((float) i / 10) * 0.514444); /* meters/second */ + if (i != 10000) WAYPT_SET(wpt, speed, KNOTS_TO_MPS((float) i / 10)); /* meters/second */ i = be_read16(&data->course); if (i != 4000) WAYPT_SET(wpt, course, (float) i / 10); @@ -201,9 +198,9 @@ read_track_point(cetus_track_point_t *data, const time_t basetime) static void -read_tracks(const struct pdb *pdb) +read_tracks(const pdbfile *pdb) { - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; int reclen, records, total, points, dropped; char descr[(2 * TRACK_POINT_SIZE) + 1]; char temp_descr[TRACK_POINT_SIZE + 1]; @@ -220,7 +217,7 @@ read_tracks(const struct pdb *pdb) dropped = 0; basetime = 0; - for (pdb_rec = pdb->rec_index.rec; pdb_rec != NULL; pdb_rec = pdb_rec->next) + for (pdb_rec = pdb->rec_list; pdb_rec; pdb_rec = pdb_rec->next) { int i, magic; char *c = (char *)pdb_rec->data; @@ -294,13 +291,13 @@ read_tracks(const struct pdb *pdb) } static void -read_waypts(const struct pdb *pdb) +read_waypts(const pdbfile *pdb) { struct cetus_wpt_s *rec; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; char *vdata; - for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) + for(pdb_rec = pdb->rec_list; pdb_rec; pdb_rec = pdb_rec->next) { waypoint *wpt_tmp; int i; @@ -369,13 +366,13 @@ read_waypts(const struct pdb *pdb) static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); if ( dbname ) { xfree(dbname); dbname = NULL; @@ -385,14 +382,15 @@ rd_deinit(void) static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); out_fname = fname; + ct = 0; } static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); if ( dbname ) { xfree(dbname); dbname = NULL; @@ -402,11 +400,7 @@ wr_deinit(void) static void data_read(void) { - struct pdb *pdb; - - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } + pdbfile *pdb = file_in; if (pdb->creator != MYCREATOR) fatal(MYNAME ": Not a Cetus file.\n"); @@ -420,7 +414,6 @@ data_read(void) read_waypts(pdb); break; } - free_pdb(pdb); } @@ -428,7 +421,6 @@ static void cetus_writewpt(const waypoint *wpt) { struct cetus_wpt_s *rec; - static int ct; struct tm *tm; char *vdata; char *desc_long; @@ -541,15 +533,8 @@ cetus_writewpt(const waypoint *wpt) } vdata += strlen( vdata ) + 1; - opdb_rec = new_Record (0, 2, ct++, (uword) (vdata-(char *)rec), (const ubyte *)rec); + pdb_write_rec(file_out, 0, 2, ct++, rec, (char *)vdata - (char *)rec); - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } - - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } xfree(rec); } @@ -580,22 +565,18 @@ data_write(void) setshort_length(mkshort_wr_handle, 15); setshort_whitespace_ok(mkshort_wr_handle, 0); - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - if ( dbname ) { - strncpy( opdb->name, dbname, PDB_DBNAMELEN ); + strncpy( file_out->name, dbname, PDB_DBNAMELEN ); } else { - strncpy(opdb->name, out_fname, PDB_DBNAMELEN); + strncpy(file_out->name, out_fname, PDB_DBNAMELEN); } - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; - opdb->type = MYTYPE_WPT; /* CWpt */ - opdb->creator = MYCREATOR; /* cGPS */ - opdb->version = 1; + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->type = MYTYPE_WPT; /* CWpt */ + file_out->creator = MYCREATOR; /* cGPS */ + file_out->version = 1; /* * All this is to sort by waypoint names before going to Cetus. @@ -622,7 +603,6 @@ data_write(void) cetus_writewpt(htable[i].wpt); } - pdb_Write(opdb, fileno(file_out)); xfree(htable); mkshort_del_handle(&mkshort_wr_handle); } diff --git a/coldsync/Artistic b/coldsync/Artistic deleted file mode 100644 index 98299f957..000000000 --- a/coldsync/Artistic +++ /dev/null @@ -1,131 +0,0 @@ -$Id: Artistic,v 1.1 2002/08/16 15:54:46 robertl Exp $ - - - - The "Artistic License" - - Preamble - -The intent of this document is to state the conditions under which a -Package may be copied, such that the Copyright Holder maintains some -semblance of artistic control over the development of the package, -while giving the users of the package the right to use and distribute -the Package in a more-or-less customary fashion, plus the right to make -reasonable modifications. - -Definitions: - - "Package" refers to the collection of files distributed by the - Copyright Holder, and derivatives of that collection of files - created through textual modification. - - "Standard Version" refers to such a Package if it has not been - modified, or has been modified in accordance with the wishes - of the Copyright Holder as specified below. - - "Copyright Holder" is whoever is named in the copyright or - copyrights for the package. - - "You" is you, if you're thinking about copying or distributing - this Package. - - "Reasonable copying fee" is whatever you can justify on the - basis of media cost, duplication charges, time of people involved, - and so on. (You will not be required to justify it to the - Copyright Holder, but only to the computing community at large - as a market that must bear the fee.) - - "Freely Available" means that no fee is charged for the item - itself, though there may be fees involved in handling the item. - It also means that recipients of the item may redistribute it - under the same conditions they received it. - -1. You may make and give away verbatim copies of the source form of the -Standard Version of this Package without restriction, provided that you -duplicate all of the original copyright notices and associated disclaimers. - -2. You may apply bug fixes, portability fixes and other modifications -derived from the Public Domain or from the Copyright Holder. A Package -modified in such a way shall still be considered the Standard Version. - -3. You may otherwise modify your copy of this Package in any way, provided -that you insert a prominent notice in each changed file stating how and -when you changed that file, and provided that you do at least ONE of the -following: - - a) place your modifications in the Public Domain or otherwise make them - Freely Available, such as by posting said modifications to Usenet or - an equivalent medium, or placing the modifications on a major archive - site such as uunet.uu.net, or by allowing the Copyright Holder to include - your modifications in the Standard Version of the Package. - - b) use the modified Package only within your corporation or organization. - - c) rename any non-standard executables so the names do not conflict - with standard executables, which must also be provided, and provide - a separate manual page for each non-standard executable that clearly - documents how it differs from the Standard Version. - - d) make other distribution arrangements with the Copyright Holder. - -4. You may distribute the programs of this Package in object code or -executable form, provided that you do at least ONE of the following: - - a) distribute a Standard Version of the executables and library files, - together with instructions (in the manual page or equivalent) on where - to get the Standard Version. - - b) accompany the distribution with the machine-readable source of - the Package with your modifications. - - c) give non-standard executables non-standard names, and clearly - document the differences in manual pages (or equivalent), together - with instructions on where to get the Standard Version. - - d) make other distribution arrangements with the Copyright Holder. - -5. You may charge a reasonable copying fee for any distribution of this -Package. You may charge any fee you choose for support of this -Package. You may not charge a fee for this Package itself. However, -you may distribute this Package in aggregate with other (possibly -commercial) programs as part of a larger (possibly commercial) software -distribution provided that you do not advertise this Package as a -product of your own. You may embed this Package's interpreter within -an executable of yours (by linking); this shall be construed as a mere -form of aggregation, provided that the complete Standard Version of the -interpreter is so embedded. - -6. The scripts and library files supplied as input to or produced as -output from the programs of this Package do not automatically fall -under the copyright of this Package, but belong to whoever generated -them, and may be sold commercially, and may be aggregated with this -Package. If such scripts or library files are aggregated with this -Package via the so-called "undump" or "unexec" methods of producing a -binary executable image, then distribution of such an image shall -neither be construed as a distribution of this Package nor shall it -fall under the restrictions of Paragraphs 3 and 4, provided that you do -not represent such an executable image as a Standard Version of this -Package. - -7. C subroutines (or comparably compiled subroutines in other -languages) supplied by you and linked into this Package in order to -emulate subroutines and variables of the language defined by this -Package shall not be considered part of this Package, but are the -equivalent of input as in Paragraph 6, provided these subroutines do -not change the language in any way that would cause it to fail the -regression tests for the language. - -8. Aggregation of this Package with a commercial distribution is always -permitted provided that the use of this Package is embedded; that is, -when no overt attempt is made to make this Package's interfaces visible -to the end user of the commercial distribution. Such use shall not be -construed as a distribution of this Package. - -9. The name of the Copyright Holder may not be used to endorse or promote -products derived from this software without specific prior written permission. - -10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED -WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - - The End diff --git a/coldsync/Makefile b/coldsync/Makefile deleted file mode 100644 index e69de29bb..000000000 diff --git a/coldsync/Makefile.in b/coldsync/Makefile.in deleted file mode 100644 index e69de29bb..000000000 diff --git a/coldsync/README b/coldsync/README deleted file mode 100644 index 0d97b54aa..000000000 --- a/coldsync/README +++ /dev/null @@ -1,211 +0,0 @@ - This is ColdSync, a tool for synchronizing data between Palm -devices and Unix workstations. - - Copyright (C) 1999-2001, Andrew Arensburger. - - The latest version of this package is available at - http://www.ooblick.com/software/coldsync/ - - This package is distributable under the terms of the Artistic -License. You should have received a file called "Artistic", which -specifies the terms under which this package may be distributed and -modified. - The Artistic License is taken from the Perl 5.005_03 -distribution, so some of the text is specific to Perl and does not -apply to ColdSync. I hope to address this in a future release. - - This product includes software developed by the University of -California, Berkeley and its contributors. - - This product includes software developed by the Apache Group -for use in the Apache HTTP server project (http://www.apache.org/). - (Actually, the Apache code in question was written by Panos -Tsirigotis. See comments in "src/ap_snprintf.c".) - - ---------------------------------------- - -* WHAT IS COLDSYNC? - - ColdSync is a tool for synchronizing data between Palm -computing devices (such as the PalmPilot, PalmPilot Pro, Palm V, -QualComm PDQ, Handspring Visor and so forth), and a Unix workstation. - ColdSync can back up and restore the state of a Palm, as well -as synchronize its data, which is sort of like a two-way rdist (see -below). In future versions, it will be possible to do more interesting -things with this data. - -* WHAT YOU'LL NEED - - - A POSIX-compliant operating system, preferably some flavor - of Unix - - An ANSI C compiler - - An ANSI C++ compiler - - Perl 5.005_03 or later (though earlier versions might work) - -* BUILDING AND INSTALLING COLDSYNC - - If you've built GNU software before, this should be familiar -territory. You should be able to just - - ./configure - make - make install - -Full details are provided in the "INSTALL" file. - -* WHAT IS SYNCHRONIZING? - - Synchronizing, also referred to as "syncing" refers to the -process of examining two databases (everything on the Palm is a -database) to see how they differ, and updating them so that they are -identical. - Syncing is different from just overwriting one database with -the other. For instance, if you add an entry for "Aunt Mabel" in your -Palm's address book, and an entry for "Uncle Bob" on your desktop -machine, then you don't want to just copy the address book from the -Palm to the desktop or vice-versa: that would delete one of the -entries that you just created. When you sync with ColdSync, you'll -wind up with both entries, on both the Palm and the desktop. - - Another difference between synchronizing and blind copying -lies in the fact that PalmOS has facilities to support syncing. If you -have 2000 entries in your Palm address book and want to copy them to -the desktop, it'll take a rather long time to copy them over a -relatively slow serial connection. When it syncs, ColdSync copies only -those records that have changed. - - ColdSync tries to be very cautious when it syncs, and not -delete any information unless it is sure that that is the right thing -to do. Its attitude is that it's better to err on the side of caution, -and maybe make you delete something twice, than it is to delete some -crucial bit of information. - -* SECURITY CONSIDERATIONS - - ColdSync is not secure. Period. - I have tried to pay due attention to security considerations, -but the sync process itself is inherently insecure. When ColdSync, -running on a workstation, receives a connection from a Palm, it has no -reliable way of knowing that the Palm on the other end is in fact the -one that it claims to be. - Likewise, when a Palm syncs with a workstation (whether that -workstation is using ColdSync or Palm's own HotSync), it has no -reliable way of knowing that the workstation is the one that it claims -to be. - PalmOS allows you to mark records as "private." This doesn't -mean a thing when you sync: the private and non-private records are -treated equally. In particular, anyone who has physical access to your -Palm can download your private records. - - There may be a Palm utility out there that will encrypt each -record in a database before a sync, but I don't know of any such -utility. - -* INTERNATIONALIZATION - - ColdSync includes some internationalization (i18n) support. It -is believed to work on all platforms with a Uniforum-compliant libintl -(gettext()). ColdSync does not work with XPG i18n (catgets() etc.). - However, you need GNU xgettext to compile the message catalog -("i18n/messages.po") from the source files. - - ---------------------------------------- - -COMPATIBILITY NOTES - -* ColdSync 2.2.4 - -FreeBSD: - This package was developed under FreeBSD 3.x/4.x, and compiles - cleanly with no modification under 4.2-RELEASE. - - On newer versions of FreeBSD (4.0 and beyond), it's possible - to communicate with the Handspring Visor using its USB - interface. Configure a listen type of "usb" rather than - "serial", and use device /dev/ugen0. - -Redhat Linux 6.2 (also Debian, and probably others): - (as of ColdSync v1.6.6-20010130) - Compiles cleanly with no modifications. Runs fine. - - The Linux serial device driver appears to drop characters at - random. As a result, you may see a lot of - - ##### Got an unexpected data packet. Sending an ACK to shut it up. - - messages. - -Solaris 2.7: - (as of v2.2.4) - There are still some problems with ColdSync's IPv6 code under - Solaris 2.6 and later. You'll need to use - ./configure --without-ipv6 - - (as of v2.2.0-20010805) - Compiles with Sun Forte 6U1. - - ColdSync is known not to work with Sun's i18n utilities. - ColdSync should detect this, and disable i18n. - -Digital Unix 4.0: - (as of ColdSync v2.4.4-20011113) - DEC's linker chokes on the overly-long identifiers produced by - the STL. GNU ld might work. - - (as of ColdSync v1.6.6-20010130) - Compiles with gcc 2.7.2. Compilation prints several warnings; - they appear to be benign: - - PConnection_serial.c:444: warning: implicit declaration of function `cfmakeraw' - PConnection_net.c:281: warning: passing arg 6 of `_Erecvfrom' from incompatiblepointer type - PConnection_net.c:674: warning: passing arg 6 of `_Erecvfrom' from incompatiblepointer type - PConnection_net.c:872: warning: passing arg 3 of `_Eaccept' from incompatible pointer type - config.c:964: warning: overflow in implicit constant conversion - GenericConduit.cc:82: warning: unused parameter `const struct conduit_block * block' - - If you are using DEC's C compiler, I suggest the following - compiler flags: - -std1 -msg_enable level3 - - -AIX 4.1: - (as of ColdSync v1.1.2) - Compiles with gcc 2.7.2, but when linking, complains that: - - ld: 0711-224 WARNING: Duplicate symbol: _IO_cleanup_registration_needed - ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. - - This may be a problem with the installation, though (the same - thing happens when compiling "Hello, world"). - - I've only compiled it. I don't know whether it actually runs. - -If you have any updated information, please send it in to the -maintainer (arensb@ooblick.com). My testing pool isn't as large as it -once was. - -Windows NT: - (as of ColdSync 1.4.5) - To the best of my knowledge, ColdSync compiles and runs under - Windows NT with the Cygwin tools. - - However, ColdSync was written as a Unix tool. Windows users - have the HotSync desktop tools from Palm, which work quite - well. If ColdSync works under Windows, that's wonderful, but - I'm not going to let Windows compatibility get in the way of - Unix development. - -MacOS X: - (as of ColdSync 1.4.6) - - According to one correspondent, ColdSync compiles and runs - with no problems under MacOS X. - The serial port should be /dev/ttyd.printer . - - ---------------------------------------- - -BUGS: - If you create a Memo record, delete it without leaving the -editor, and check the "Save archive copy on PC" box, it will be -archived, but the archived record may contain trailing garbage. - This is due to a bug in PalmOS (as of 3.0). diff --git a/coldsync/README.gpsbabel b/coldsync/README.gpsbabel deleted file mode 100644 index 6315fcad4..000000000 --- a/coldsync/README.gpsbabel +++ /dev/null @@ -1,10 +0,0 @@ -This directory is a subset of coldsync-2.2.5. GPSbabel needs very -limited set of that functionality to read and write Palm/OS files. -I was faced with either reimplementing it (and I DON'T want to -become a Palm/OS expert) or cribbing the code. Since it's all under -Artistic license, I took libpdb and the includes, whacked out the most -horribly non-portable pieces, jacked in a constant config.h, and pointed -the makefiles to it. - -Thanx to the ColdSync guys for figuring this stuff out! - diff --git a/coldsync/cs-config.h b/coldsync/cs-config.h deleted file mode 100644 index 69eadd99c..000000000 --- a/coldsync/cs-config.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Assume we're on a conformant ISO C platform. - */ - - -#define STDC_HEADERS 1 -#define _(str) str -#define inline diff --git a/coldsync/palm.h b/coldsync/palm.h deleted file mode 100644 index 2b111d532..000000000 --- a/coldsync/palm.h +++ /dev/null @@ -1,55 +0,0 @@ -/* palm.h - * Definitions of various types that PalmOS likes to use. - * - * Copyright (C) 2001, Andrew Arensburger. - * You may distribute this file under the terms of the Artistic - * License, as specified in the README file. - * - * $Id: palm.h,v 1.2 2005/10/24 18:26:30 robertl Exp $ - */ -#ifndef _palm_h_ -#define _palm_h_ - -#include "../gbtypes.h" - -/* Convenience types */ -typedef signed char byte; /* Signed 8-bit quantity */ -typedef unsigned char ubyte; /* Unsigned 8-bit quantity */ -typedef gbint16 word; /* Signed 16-bit quantity */ -typedef gbuint16 uword; /* Unsigned 16-bit quantity */ -typedef gbint32 dword; /* Signed 32-bit quantity */ -typedef gbuint32 udword; /* Unsigned 32-bit quantity */ - -typedef udword chunkID; /* Those IDs made up of four - * characters stuck together into a - * 32-bit quantity. - */ - -/* Explicitly define the sizes of types. Can't depend on the host's types - * having the same size as the Palm. For instance, Alphas are 64-bit - * machines, so 'unsigned long' is 8 bytes, whereas 'udword' is only 4 - * bytes. - */ -#define SIZEOF_BYTE 1 -#define SIZEOF_UBYTE 1 -#define SIZEOF_WORD 2 -#define SIZEOF_UWORD 2 -#define SIZEOF_DWORD 4 -#define SIZEOF_UDWORD 4 - -/* MAKE_CHUNKID - * A convenience macro to make a chunkID out of four characters. - */ -#define MAKE_CHUNKID(a,b,c,d) \ - (((a) << 24) | \ - ((b) << 16) | \ - ((c) << 8) | \ - (d)) - -/* XXX - There ought to be something to make sure that the sizes and - * signedness above are true. - */ - -typedef enum { False = 0, True = 1 } Bool; - -#endif /* _palm_h_ */ diff --git a/coldsync/pconn/util.h b/coldsync/pconn/util.h deleted file mode 100644 index 17d3c59d0..000000000 --- a/coldsync/pconn/util.h +++ /dev/null @@ -1,60 +0,0 @@ -/* util.h - * Misc. useful stuff. - * - * Copyright (C) 1999-2000, Andrew Arensburger. - * You may distribute this file under the terms of the Artistic - * License, as specified in the README file. - * - * $Id: util.h,v 1.2 2002/08/24 03:01:31 robertl Exp $ - */ -#ifndef _util_h_ -#define _util_h_ - -#include -#include -#include "palm.h" - -/* XXX - The functions declared INLINE, below, really ought to be inline - * functions. I'm not sure how to do this portably, though. - */ -#ifdef __GNUC__ -# define INLINE __inline__ -#else -# define INLINE -#endif /* __GNUC__ */ - -/* Functions for reading a value from an array of ubytes */ -extern INLINE ubyte peek_ubyte(const ubyte *buf); -extern INLINE uword peek_uword(const ubyte *buf); -extern INLINE udword peek_udword(const ubyte *buf); - -/* Functions for extracting values from an array of ubytes */ -extern INLINE ubyte get_ubyte(const ubyte **buf); -extern INLINE uword get_uword(const ubyte **buf); -extern INLINE udword get_udword(const ubyte **buf); - -/* Functions for writing values to an array of ubytes */ -extern INLINE void put_ubyte(ubyte **buf, const ubyte value); -extern INLINE void put_uword(ubyte **buf, const uword value); -extern INLINE void put_udword(ubyte **buf, const udword value); - -#if TIME -/* Functions for converting between DLP's time format and Unix's - * time_ts and the time_t-with-offset that the rest of the Palm stuff - * uses. - */ -extern time_t time_dlp2time_t(const struct dlp_time *dlpt); -extern udword time_dlp2palmtime(const struct dlp_time *dlpt); -extern void time_time_t2dlp(const time_t t, struct dlp_time *dlpt); -extern void time_palmtime2dlp(const udword palmt, struct dlp_time *dlpt); - -extern void debug_dump(FILE *outfile, const char *prefix, - const ubyte *buf, const udword len); -#endif -#endif /* _util_h_ */ - - /* This is for Emacs's benefit: - * Local Variables: *** - * fill-column: 75 *** - * End: *** - */ diff --git a/coldsync/pdb.c b/coldsync/pdb.c deleted file mode 100644 index 161efc64c..000000000 --- a/coldsync/pdb.c +++ /dev/null @@ -1,2038 +0,0 @@ -/* pdb.c - * - * Functions for dealing with Palm databases and such. - * - * Copyright (C) 1999-2001, Andrew Arensburger. - * You may distribute this file under the terms of the Artistic - * License, as specified in the README file. - * - * $Id: pdb.c,v 1.12 2006/07/13 03:27:53 robertl Exp $ - */ -/* XXX - The way zero-length records are handled is a bit of a kludge. They - * shouldn't normally exist, with the exception of expunged records. But, - * of course, a malformed conduit or something can create them. - * The half-assed way they're handled here is to a) not upload zero-length - * records to the Palm, b) warn the user if they're written to a file, c) - * provide a utility (in the p5-Palm package) to delete zero-length - * records. - */ -/* XXX - This is a library. It shouldn't print error messages. - * Add 'int pdb_errno'; define error numbers and error messages that go - * with them. - * Debugging messages should go to 'FILE *pdb_logfile'. - */ -#include "config.h" -#if PDBFMTS_ENABLED - -#include "cs-config.h" -#include -#include /* For open() */ -#include -/* - * Unistd.h (indeed, read, write, and lseek) are not part of ISO C. - * Systems may not have unistd.h. While the below is tacky, Windows - * is the only system that we care about that has lseek and friends - * but doesn't have it prototyped. Systems with 64-bit file I/O but - * based on LP64 model (i.e. OS/X) _require_ the prototype for lseek. - */ -#if defined (__WIN32__) -#include -#define lseek _lseek -#define write _write -#define read _read -#define close _close -#else -#include -#endif -#include -#include - -#if STDC_HEADERS -# include /* For strncat(), memcpy() et al. */ -#else /* STDC_HEADERS */ -# ifndef HAVE_STRCHR -# define strchr index -# define strrchr rindex -# endif /* HAVE_STRCHR */ -# ifndef HAVE_MEMCPY -# define memcpy(d,s,n) bcopy ((s), (d), (n)) -# define memmove(d,s,n) bcopy ((s), (d), (n)) -# endif /* HAVE_MEMCPY */ -#endif /* STDC_HEADERS */ - -/* XXX - Is this right? Should this be in the "else" clause, above? */ -#if HAVE_STRINGS_H -# include /* For bzero() */ -#endif /* HAVE_STRINGS_H */ - -#if HAVE_LIBINTL_H -# include /* For i18n */ -#endif /* HAVE_LIBINTL_H */ - -#include -#include "pdb.h" - -/* XXX - The functions declared INLINE, below, really ought to be inline - * functions. I'm not sure how to do this portably, though. - */ -#ifdef __GNUC__ -# define INLINE __inline__ -#else -# define INLINE -#endif /* __GNUC__ */ - -/* Functions for extracting values from an array of ubytes */ -extern INLINE ubyte get_ubyte(const ubyte **buf); -extern INLINE uword get_uword(const ubyte **buf); -extern INLINE udword get_udword(const ubyte **buf); - -/* Functions for writing values to an array of ubytes */ -extern INLINE void put_ubyte(ubyte **buf, const ubyte value); -extern INLINE void put_uword(ubyte **buf, const uword value); -extern INLINE void put_udword(ubyte **buf, const udword value); -extern void debug_dump(FILE *outfile, const char *prefix, - const ubyte *buf, const udword len); - -int pdb_trace = 0; /* Debugging level for PDB stuff */ -#define PDB_TRACE(n) if (pdb_trace >= (n)) - -/* Helper functions */ -static uword get_file_length(int fd); -int pdb_LoadHeader(int fd, struct pdb *db); - /* pdb_LoadHeader() is visible to other files */ -static int pdb_LoadRecListHeader(int fd, struct pdb *db); -static int pdb_LoadRsrcIndex(int fd, struct pdb *db); -static int pdb_LoadRecIndex(int fd, struct pdb *db); -static int pdb_LoadAppBlock(int fd, struct pdb *db); -static int pdb_LoadSortBlock(int fd, struct pdb *db); -static int pdb_LoadResources(int fd, struct pdb *db); -static int pdb_LoadRecords(int fd, struct pdb *db); - -/* merge_attributes - * Takes a record's flags and category, and merges them into a single byte, - * with the flags in the top nybble and the category in the bottom one - */ -static inline ubyte -merge_attributes(const ubyte flags, - const ubyte category) -{ - /* The PDB_REC_ARCHIVED flag is troublesome, since it overlaps the - * category field. The idea here is that if the record was deleted, - * then it doesn't have a category anymore, so the category part - * gets set to 0. - */ - if ((flags & PDB_REC_DELETED) == 0) - return (flags & 0xf0) | - (category & 0x0f); - else - return (flags & 0xf8); -} - -/* split_attributes - * The converse of merge_attributes(). Takes the combined field attributes - * and writes its contents to *flags and *category, using the same rules as - * merge_attributes(), above. - */ -static inline void -split_attributes(const ubyte attributes, - ubyte *flags, - ubyte *category) -{ - if ((attributes & PDB_REC_DELETED) == 0) - { - *flags = (attributes & 0xf0); - *category = (attributes & 0x0f); - } else { - *flags = (attributes & 0xf8); - *category = 0; - } - PDB_TRACE(6) - fprintf(stderr, "split 0x%02x into 0x%02x, 0x%02x\n", - attributes, *flags, *category); -} - -/* new_pdb - * struct pdb constructor. - */ -struct pdb * -new_pdb() -{ - struct pdb *retval; - - /* Allocate the new pdb */ - if ((retval = (struct pdb *) malloc(sizeof(struct pdb))) == NULL) - /* Out of memory */ - return NULL; - - /* Write zeros all over it, just for safety */ - memset((void *) retval, 0, sizeof(struct pdb)); - - return retval; -} - -/* pdb_FreeRecord - * Free a previously-allocated 'pdb_record'. This function wouldn't really - * be necessary, except that pdb_CopyRecord() returns a 'pdb_record'. - */ -void -pdb_FreeRecord(struct pdb_record *rec) -{ - if (rec->data != NULL) - free(rec->data); - free(rec); -} - -/* pdb_FreeResource - * Free a previously-allocated 'pdb_resource'. This function wouldn't - * really be necessary, except that pdb_CopyResource() returns a - * 'pdb_resource'. - */ -void -pdb_FreeResource(struct pdb_resource *rsrc) -{ - if (rsrc->data != NULL) - free(rsrc->data); - free(rsrc); -} - -/* free_pdb - * Cleanly free a struct pdb, and all of its subparts (destructor). - */ -void -free_pdb(struct pdb *db) -{ - PDB_TRACE(7) - fprintf(stderr, "Inside free_pdb(%p)\n", (void *) db); - - if (db == NULL) - /* Trivial case */ - return; - - /* Free the array of records/resources */ - if (IS_RSRC_DB(db)) - { - /* It's a resource database */ - struct pdb_resource *rsrc; - struct pdb_resource *next; - - PDB_TRACE(8) - fprintf(stderr, "Freeing resource list\n"); - - /* Walk the linked list, freeing as we go along */ - for (rsrc = db->rec_index.rsrc; - rsrc != NULL; - rsrc = next) - { - next = rsrc->next; /* Remember the next - * element on the list. We - * won't have a chance to - * look it up after this - * one has been free()d. - */ - - /* Free this element */ - pdb_FreeResource(rsrc); - } - } else { - /* It's a record database */ - struct pdb_record *rec; - struct pdb_record *next; - - PDB_TRACE(8) - fprintf(stderr, "Freeing record list\n"); - - /* Walk the linked list, freeing as we go along */ - for (rec = db->rec_index.rec; - rec != NULL; - rec = next) - { - next = rec->next; /* Remember the next - * element on the list. We - * won't have a chance to - * look it up after this - * one has been free()d. - */ - - /* Free this element */ - pdb_FreeRecord(rec); - } - } - - /* Free the sort block */ - if (db->sortinfo != NULL) - free(db->sortinfo); - - /* Free the app info block */ - if (db->appinfo != NULL) - free(db->appinfo); - - free(db); -} - -/* pdb_Read - * Read a PDB from the file descriptor 'fd'. This must already have been - * opened for reading and/or writing. - * - * Note: this function does not to any locking. The caller is responsible - * for that. - */ -struct pdb * -pdb_Read(int fd) -{ - int err; - struct pdb *retval; - - /* Create a new pdb to return */ - if ((retval = new_pdb()) == NULL) - { - return NULL; - } - - /* Find out how long the file is */ - retval->file_size = get_file_length(fd); - if (retval->file_size == ~0) - { - /* The file isn't seekable */ - fprintf(stderr, _("File isn't seekable.\n")); - free_pdb(retval); - return NULL; - } - - /* Load the header */ - if ((err = pdb_LoadHeader(fd, retval)) < 0) - { - fprintf(stderr, _("Can't load header.\n")); - free_pdb(retval); - return NULL; - } - - /* Load the record list header */ - if ((err = pdb_LoadRecListHeader(fd, retval)) < 0) - { - fprintf(stderr, _("Can't load record list header for " - "\"%.*s\".\n"), - PDB_DBNAMELEN, retval->name); - free_pdb(retval); - return NULL; - } - - /* Read the record/resource list */ - if (IS_RSRC_DB(retval)) - { - /* Read the resource index */ - if ((err = pdb_LoadRsrcIndex(fd, retval)) < 0) - { - fprintf(stderr, _("Can't read resource index for " - "\"%.*s\".\n"), - PDB_DBNAMELEN, retval->name); - free_pdb(retval); - return NULL; - } - } else { - /* Read the record index */ - if ((err = pdb_LoadRecIndex(fd, retval)) < 0) - { - fprintf(stderr, _("Can't read record index for " - "\"%.*s\".\n"), - PDB_DBNAMELEN, retval->name); - free_pdb(retval); - return NULL; - } - } - - /* In most PDBs, there are two NUL bytes here. They are allowed by - * the spec, but not mandated, and some PDBs don't have them. We'll - * ignore them for now, and have the appropriate pdb_Load*() - * function lseek() to the proper position. - */ - - /* Load the AppInfo block, if any */ - if ((err = pdb_LoadAppBlock(fd, retval)) < 0) - { - fprintf(stderr, _("Can't read AppInfo block for " - "\"%.*s\".\n"), - PDB_DBNAMELEN, retval->name); - free_pdb(retval); - return NULL; - } - - /* Load the sort block, if any */ - if ((err = pdb_LoadSortBlock(fd, retval)) < 0) - { - fprintf(stderr, _("Can't read sort block for " - "\"%.*s\".\n"), - PDB_DBNAMELEN, retval->name); - free_pdb(retval); - return NULL; - } - - /* Load the records themselves */ - if (IS_RSRC_DB(retval)) - { - /* Read the resources */ - if ((err = pdb_LoadResources(fd, retval)) < 0) - { - fprintf(stderr, _("Can't read resources for " - "\"%.*s\".\n"), - PDB_DBNAMELEN, retval->name); - free_pdb(retval); - return NULL; - } - } else { - /* Read the records */ - if ((err = pdb_LoadRecords(fd, retval)) < 0) - { - fprintf(stderr, _("Can't read records for " - "\"%.*s\".\n"), - PDB_DBNAMELEN, retval->name); - free_pdb(retval); - return NULL; - } - } - - return retval; /* Success */ -} - -/* pdb_Write - * Write 'db' to the file descriptor 'fd'. This must already have been - * opened for writing. - * - * Note that while you can open the backup file for reading and writing, - * read from it with pdb_Read() and save it with pdb_Write(), this is not - * recommended: if anything should go wrong at the wrong time (e.g., the - * disk fills up just as you're about to write the database back to disk), - * you will lose the entire backup. - * A better approach is to use a staging file: read from the backup file, - * write to a temporary file, then use rename() to move the temporary file - * onto the real one. Alternately, you can copy the original file to a - * temporary one, then open the temporary for both reading and writing. - * This might have some advantages, in that it allows you to lock a single - * file for the duration of the sync. - * - * Note: this function does not lock the file. The caller is responsible - * for that. - */ -int -pdb_Write(const struct pdb *db, - int fd) -{ - static ubyte header_buf[PDB_HEADER_LEN]; - /* Buffer for writing database header */ - static ubyte rlheader_buf[PDB_RECORDLIST_LEN]; - /* Buffer for writing the record list header */ - static ubyte nul_buf[2]; - /* Buffer for writing the two useless NULs */ - ubyte *wptr; /* Pointer into buffers, for writing */ - udword offset; /* The next offset we're interested in */ - - /* Initialize 'offset': the next variable-sized item will go after - * the header, after the index header, after the index, after the - * two useless NULs. - */ - offset = PDB_HEADER_LEN + PDB_RECORDLIST_LEN; - if (IS_RSRC_DB(db)) - offset += db->numrecs * PDB_RESOURCEIX_LEN; - else - offset += db->numrecs * PDB_RECORDIX_LEN; - offset += 2; /* Those two useless NUL bytes */ - - /** Write the database header **/ - - /* Construct the header in 'header_buf' */ - wptr = header_buf; - memcpy(wptr, db->name, PDB_DBNAMELEN); - wptr += PDB_DBNAMELEN; - put_uword(&wptr, (uword) (db->attributes & ~PDB_ATTR_OPEN)); - /* Clear the 'open' flag before writing */ - put_uword(&wptr, db->version); - put_udword(&wptr, db->ctime); - put_udword(&wptr, db->mtime); - put_udword(&wptr, db->baktime); - put_udword(&wptr, db->modnum); - if (db->appinfo == NULL) /* Write the AppInfo block, if any */ - /* This database doesn't have an AppInfo block */ - put_udword(&wptr, 0L); - else { - /* This database has an AppInfo block */ - put_udword(&wptr, offset); - offset += db->appinfo_len; - } - if (db->sortinfo == NULL) /* Write the sort block, if any */ - /* This database doesn't have a sort block */ - put_udword(&wptr, 0L); - else { - put_udword(&wptr, offset); - offset += db->sortinfo_len; - } - put_udword(&wptr, db->type); - put_udword(&wptr, db->creator); - put_udword(&wptr, db->uniqueIDseed); - - /* Write the database header */ - if (write(fd, header_buf, PDB_HEADER_LEN) != PDB_HEADER_LEN) - { - fprintf(stderr, _("%s: can't write database header for " - "\"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - close(fd); - return -1; - } - - /** Write the record/resource index header **/ - /* Construct the record list header */ - wptr = rlheader_buf; - put_udword(&wptr, 0L); /* nextID */ - /* XXX - What is this? Should this be something - * other than 0? */ - put_uword(&wptr, db->numrecs); - - /* Write the record list header */ - if (write(fd, rlheader_buf, PDB_RECORDLIST_LEN) != PDB_RECORDLIST_LEN) - { - fprintf(stderr, _("%s: can't write record list header for " - "\"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - return -1; - } - - /* Write the record/resource index */ - if (IS_RSRC_DB(db)) - { - /* It's a resource database */ - struct pdb_resource *rsrc; /* Current resource */ - - /* Go through the list of resources, writing each one */ - for (rsrc = db->rec_index.rsrc; - rsrc != NULL; - rsrc = rsrc->next) - { - static ubyte rsrcbuf[PDB_RESOURCEIX_LEN]; - /* Buffer to hold the resource - * index entry. - */ - - /* Construct the resource index entry */ - wptr = rsrcbuf; - put_udword(&wptr, rsrc->type); - put_uword(&wptr, rsrc->id); - put_udword(&wptr, offset); - - /* Write the resource index entry */ - if (write(fd, rsrcbuf, PDB_RESOURCEIX_LEN) != - PDB_RESOURCEIX_LEN) - { - fprintf(stderr, _("%s: Can't write resource " - "index entry for " - "\"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - return -1; - } - - /* Bump 'offset' up to point to the offset of the - * next variable-sized thing in the file. - */ - offset += rsrc->data_len; - } - } else { - /* It's a record database */ - struct pdb_record *rec; /* Current record */ - - /* Go through the list of records, writing each one */ - for (rec = db->rec_index.rec; rec != NULL; rec = rec->next) - { - static ubyte recbuf[PDB_RECORDIX_LEN]; - /* Buffer to hold the record index - * entry. - */ - - /* Construct the record index entry */ - wptr = recbuf; - - /* Sanity check */ - if (rec->data_len == 0) - { - fprintf(stderr, - _("\"%.*s\" record 0x%08lx has " - "length 0.\n"), - PDB_DBNAMELEN, db->name, - (unsigned long) rec->id); - } - - put_udword(&wptr, offset); - put_ubyte(&wptr, merge_attributes( - rec->flags, - rec->category)); - put_ubyte(&wptr, (char) ((rec->id >> 16) & 0xff)); - put_ubyte(&wptr, (char) ((rec->id >> 8) & 0xff)); - put_ubyte(&wptr, (char) (rec->id & 0xff)); - - /* Write the resource index entry */ - if (write(fd, recbuf, PDB_RECORDIX_LEN) != - PDB_RECORDIX_LEN) - { - fprintf(stderr, _("%s: Can't write record " - "index entry for " - "\"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - return -1; - } - - /* Bump 'offset' up to point to the offset of the - * next variable-sized thing in the file. - */ - offset += rec->data_len; - } - } - - /* Write the two useless NUL bytes */ - nul_buf[0] = nul_buf[1] = '\0'; - if (write(fd, nul_buf, 2) != 2) - { - fprintf(stderr, _("%s: Can't write the two useless NULs to " - "\"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - return -1; - } - - /* Write the AppInfo block, if any */ - if (db->appinfo != NULL) - { - if (write(fd, db->appinfo, db->appinfo_len) != - db->appinfo_len) - { - fprintf(stderr, _("%s: Can't write AppInfo block for " - "\"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - return -1; - } - } - - /* Write the sort block, if any */ - if (db->sortinfo != NULL) - { - if (write(fd, db->sortinfo, db->sortinfo_len) != - db->sortinfo_len) - { - fprintf(stderr, _("%s: Can't write sort block for " - "\"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - return -1; - } - } - - /* Write the record/resource data */ - if (IS_RSRC_DB(db)) - { - /* It's a resource database */ - struct pdb_resource *rsrc; - - /* Go through the list of resources, writing each one's - * data. - */ - for (rsrc = db->rec_index.rsrc; - rsrc != NULL; - rsrc = rsrc->next) - { - /* Write the data */ - if (write(fd, rsrc->data, rsrc->data_len) != - rsrc->data_len) - { - fprintf(stderr, _("%s: Can't write resource " - "data for \"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - return -1; - } - } - } else { - /* It's a record database */ - struct pdb_record *rec; - - /* Go through the list of records, writing each one's data. */ - for (rec = db->rec_index.rec; rec != NULL; rec = rec->next) - { - /* Write the data */ - if (write(fd, rec->data, rec->data_len) != - rec->data_len) - { - fprintf(stderr, - _("%s: Can't write record data for " - "\"%.*s\".\n"), - "pdb_Write", - PDB_DBNAMELEN, db->name); - perror("write"); - return -1; - } - } - } - - return 0; /* Success */ -} - -#if 0 -/* pdb_FindRecordByID - * Find the record in 'db' whose ID is 'id'. Return a pointer to it. If no - * such record exists, or in case of error, returns NULL. - */ -struct pdb_record * -pdb_FindRecordByID( - const struct pdb *db, - const udword id) -{ - struct pdb_record *rec; - - /* Walk the list of records, comparing IDs */ - for (rec = db->rec_index.rec; rec != NULL; rec = rec->next) - { - if (rec->id == id) - return rec; - } - - return NULL; /* Couldn't find it */ -} - -/* pdb_FindRecordByIndex - * Find the 'index'th record in 'db', and return a pointer to it. If no - * such record exists, or in case of error, return NULL. - */ -struct pdb_record * -pdb_FindRecordByIndex( - const struct pdb *db, /* Database to look in */ - const uword index) /* Index of the record to look for */ -{ - struct pdb_record *rec; - int i; - - /* Walk the list, decrementing the count as we go along. If it - * reaches 0, we've found the record. - */ - rec = db->rec_index.rec; - for (i = index; i > 0; i--) - { - if (rec == NULL) - /* Oops! We've fallen off the end of the list */ - return NULL; - rec = rec->next; - } - - return rec; /* Success */ -} - -/* pdb_NextRecord - * Find the next record after 'rec' in 'db', and return a pointer to it. If - * 'rec' is the last record in the list, return NULL. - */ -struct pdb_record * -pdb_NextRecord(const struct pdb *db, /* Database to look in */ - const struct pdb_record *rec) - /* Return 'rec's successor */ -{ - return rec->next; -} - -/* pdb_DeleteRecordByID - * Find the record whose unique ID is 'id' and delete it from 'db'. If the - * record isn't found, well, that's okay; we wanted to delete it anyway. - * Returns 0 if successful, -1 in case of error. - */ -int -pdb_DeleteRecordByID( - struct pdb *db, - const udword id) -{ - struct pdb_record *rec; /* Record we're looking at */ - struct pdb_record *last; /* Last record we saw */ - - if (IS_RSRC_DB(db)) - /* This only works with record databases */ - return -1; - - /* Look through the list of records */ - last = NULL; /* Haven't seen any records yet */ - for (rec = db->rec_index.rec; rec != NULL; rec = rec->next) - { - /* See if the ID matches */ - if (rec->id == id) - { - /* Found it */ - - /* XXX - Presumably better to use pdb_FreeRecord() */ - /* Free 'rec's data */ - if (rec->data != NULL) - free(rec->data); - - /* Cut 'rec' out of the list. The first element of - * the list is a special case. - */ - if (last == NULL) - db->rec_index.rec = rec->next; - else - last->next = rec->next; - - free(rec); /* Free it */ - db->numrecs--; /* Decrement record count */ - - return 0; /* Success */ - } - - last = rec; /* Remember what we just saw */ - } - - /* Couldn't find it. Oh, well. Call it a success anyway. */ - return 0; -} -#endif - -/* pdb_AppendRecord - * Append a new record to 'db's record list. 'newrec' is not copied, so it - * is important that the caller not free it afterwards. - */ -/* XXX - Ought to make sure that the ID is unique */ -int -pdb_AppendRecord(struct pdb *db, - struct pdb_record *newrec) -{ - struct pdb_record *rec; - - /* Sanity check */ - if (IS_RSRC_DB(db)) - /* This only works with record databases */ - return -1; - - /* Check to see if the list is empty */ - if (db->rec_index.rec == NULL) - { - db->rec_index.rec = newrec; - newrec->next = NULL; - - db->numrecs++; /* Bump record counter */ - - return 0; /* Success */ - } - - /* Walk the list to find its end */ - for (rec = db->rec_index.rec; rec->next != NULL; rec = rec->next) - ; - rec->next = newrec; - newrec->next = NULL; - - db->numrecs++; /* Bump record counter */ - - return 0; /* Success */ -} - -/* pdb_AppendResource - * Append a new resource to 'db's resource list. 'newrsrc' is not copied, - * so it is important that the caller not free it afterwards. - */ -int -pdb_AppendResource(struct pdb *db, - struct pdb_resource *newrsrc) -{ - struct pdb_resource *rsrc; - - /* Sanity check */ - if (!IS_RSRC_DB(db)) - /* This only works with resource databases */ - return -1; - - /* Check to see if the list is empty */ - if (db->rec_index.rsrc == NULL) - { - db->rec_index.rsrc = newrsrc; - newrsrc->next = NULL; - - db->numrecs++; /* Bump resource counter */ - - return 0; /* Success */ - } - - /* Walk the list to find its end */ - for (rsrc = db->rec_index.rsrc; rsrc->next != NULL; rsrc = rsrc->next) - ; - rsrc->next = newrsrc; - newrsrc->next = NULL; - - db->numrecs++; /* Bump resource counter */ - - return 0; /* Success */ -} - -/* pdb_InsertRecord - * Insert 'newrec' into 'db', just after 'prev'. If 'prev' is NULL, - * 'newrec' is inserted at the beginning of the list. - * Returns 0 if successful, -1 otherwise. - * 'newrec' is not copied, so it is important that the caller not free it. - */ -int -pdb_InsertRecord(struct pdb *db, /* The database to insert into */ - struct pdb_record *prev, - /* Insert after this record */ - struct pdb_record *newrec) - /* The record to insert */ -{ - /* If 'prev' is NULL, insert at the beginning of the list */ - if (prev == NULL) - { - newrec->next = db->rec_index.rec; - db->rec_index.rec = newrec; - db->numrecs++; /* Increment record count */ - - return 0; /* Success */ - } - - /* XXX - This function doesn't actually check to make sure that - * 'prev' is in 'db'. You could really fuck yourself over with - * this. - * So make it a documented requirement. - */ - /* The new record goes in the middle of the list. Insert it. */ - newrec->next = prev->next; - prev->next = newrec; - db->numrecs++; /* Increment record count */ - - return 0; /* Success */ -} - -#if 0 -/* pdb_InsertResource - * Insert 'newrsrc' into 'db', just after 'prev'. If 'prev' is NULL, 'newrsrc' - * is inserted at the beginning of the list. - * Returns 0 if successful, -1 otherwise. - * 'newrec' is not copied, so it is important that the caller not free it. - */ -int -pdb_InsertResource(struct pdb *db, /* The database to insert into */ - struct pdb_resource *prev, - /* Insert after this resource */ - struct pdb_resource *newrsrc) - /* The resource to insert */ -{ - /* If 'prev' is NULL, insert at the beginning of the list */ - if (prev == NULL) - { - newrsrc->next = db->rec_index.rsrc; - db->rec_index.rsrc = newrsrc; - db->numrecs++; /* Increment record count */ - - return 0; /* Success */ - } - - /* XXX - This function doesn't actually check to make sure that - * 'prev' is in 'db'. You could really fuck yourself over with - * this. - * So make it a documented requirement. - */ - /* The new resource goes in the middle of the list. Insert it. */ - newrsrc->next = prev->next; - prev->next = newrsrc; - db->numrecs++; /* Increment record count */ - - return 0; /* Success */ -} -#endif - -/* new_Record - * Create a new record from the given arguments, and return a pointer to - * it. Returns NULL in case of error. - * The record data is copied, so the caller needs to take care of freeing - * 'data'. - * - * The 'attributes' and 'category' arguments are combined into one field: - * if the new record is deleted, then the category is silently dropped. - * Otherwise, the category occupies the bottom 4 bits of the - * attributes/category field. - */ -struct pdb_record * -new_Record(const ubyte flags, - const ubyte category, - const udword id, - const uword len, - const ubyte *data) -{ - struct pdb_record *retval; - - PDB_TRACE(6) - { - fprintf(stderr, "new_Record: Creating new record:\n"); - fprintf(stderr, "\tflags == 0x%02x\n", flags); - fprintf(stderr, "\tcategory == 0x%02x\n", category); - fprintf(stderr, "\tid == 0x%08lx\n", (unsigned long) id); - fprintf(stderr, "\tlen == %d\n", len); - debug_dump(stderr, "NEW", data, len); - } - - /* Allocate the record to be returned */ - if ((retval = (struct pdb_record *) malloc(sizeof(struct pdb_record))) - == NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "new_Record"); - return NULL; - } - - /* Initialize the new record */ - retval->next = NULL; - retval->offset = 0L; - retval->flags = flags; - retval->category = category; - retval->id = id; - - /* Allocate space to put the record data */ - if (len == 0) - { - /* Special case: the record has no data (e.g., this is an - * expunged record). - */ - retval->data_len = len; - retval->data = NULL; - return retval; - } - - if ((retval->data = (ubyte *) malloc(len)) == NULL) - { - /* Couldn't allocate data portion of record */ - fprintf(stderr, _("%s: can't allocate data.\n"), - "new_Record"); - free(retval); - return NULL; - } - - /* Copy the data to the new record */ - retval->data_len = len; - memcpy(retval->data, data, len); - - return retval; /* Success */ -} - -/* new_Resource - * Create a new resource from the given arguments, and return a pointer to - * it. Returns NULL in case of error. - * The resource data is copied, so the caller needs to take care of freeing - * 'data'. - */ -struct pdb_resource * -new_Resource(const udword type, - const uword id, - const uword len, - const ubyte *data) -{ - struct pdb_resource *retval; - - PDB_TRACE(6) - { - fprintf(stderr, "new_Resource: Creating new resource:\n"); - fprintf(stderr, "\ttype == 0x%08lx (%c%c%c%c)\n", - (unsigned long) type, - (int) ((type >> 24) & 0xff), - (int) ((type >> 16) & 0xff), - (int) ((type >> 8) & 0xff), - (int) (type & 0xff)); - fprintf(stderr, "\tid == 0x%04x\n", (unsigned) id); - fprintf(stderr, "\tlen == %d\n", len); - debug_dump(stderr, "NEW", data, len); - } - - /* Allocate the resource to be returned */ - if ((retval = (struct pdb_resource *) - malloc(sizeof(struct pdb_resource))) == NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "new_Resource"); - return NULL; - } - - /* Initialize the new resource */ - retval->next = NULL; - retval->offset = 0L; - retval->type = type; - retval->id = id; - - /* Allocate space to put the resource data */ - if (len == 0) - { - /* Special case: zero-length resource (dunno if this should - * ever happen, but this way we avoid malloc(0). - */ - retval->data_len = len; - retval->data = NULL; - return retval; - } - - if ((retval->data = (ubyte *) malloc(len)) == NULL) - { - /* Couldn't allocate data portion of resource */ - fprintf(stderr, _("%s: can't allocate data.\n"), - "new_Resource"); - free(retval); - return NULL; - } - - /* Copy the data to the new resource */ - retval->data_len = len; - memcpy(retval->data, data, len); - - return retval; /* Success */ -} - -/* pdb_CopyRecord - * Make a copy of record 'rec' in database 'db' (and its data), and return - * it. The new record is allocated by pdb_CopyRecord(), so the caller has - * to take care of freeing it. - * Returns a pointer to the new copy, or NULL in case of error. - */ -struct pdb_record *pdb_CopyRecord( - const struct pdb *db, - const struct pdb_record *rec) -{ - struct pdb_record *retval; - - /* Allocate the record to be returned */ - if ((retval = (struct pdb_record *) malloc(sizeof(struct pdb_record))) - == NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "pdb_CopyRecord"); - return NULL; - } - - retval->next = NULL; /* For cleanliness */ - - /* Copy the old record to the new copy */ - retval->offset = rec->offset; - retval->flags = rec->flags; - retval->category = rec->category; - retval->id = rec->id; - - /* Allocate space for the record data itself */ - if ((retval->data = (ubyte *) malloc(rec->data_len)) == NULL) - { - fprintf(stderr, _("%s: can't allocate record data for " - "\"%.*s\".\n"), - "pdb_CopyRecord", - PDB_DBNAMELEN, db->name); - free(retval); - return NULL; - } - - /* Copy the record data */ - retval->data_len = rec->data_len; - memcpy(retval->data, rec->data, retval->data_len); - - return retval; /* Success */ -} - -/* pdb_CopyResource - * Make a copy of resource 'rsrc' in database 'db' (and its data), and - * return it. The new record is allocated by pdb_CopyResource(), so the - * caller has to take care of freeing it. - * Returns a pointer to the new copy, or NULL in case of error. - */ -struct pdb_resource *pdb_CopyResource( - const struct pdb *db, - const struct pdb_resource *rsrc) -{ - struct pdb_resource *retval; - - /* Allocate the resource to be returned */ - if ((retval = (struct pdb_resource *) - malloc(sizeof(struct pdb_resource))) == NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "pdb_CopyResource"); - return NULL; - } - - retval->next = NULL; /* For cleanliness */ - - /* Copy the old resource to the new copy */ - retval->type = rsrc->type; - retval->id = rsrc->id; - retval->offset = rsrc->offset; - - /* Allocate space for the record data itself */ - if ((retval->data = (ubyte *) malloc(rsrc->data_len)) == NULL) - { - fprintf(stderr, _("%s: can't allocate resource data for " - "\"%.*s\".\n"), - "pdb_CopyResource", - PDB_DBNAMELEN, db->name); - free(retval); - return NULL; - } - - /* Copy the resource data */ - retval->data_len = rsrc->data_len; - memcpy(retval->data, rsrc->data, retval->data_len); - - return retval; /* Success */ -} - -/*** Helper functions ***/ - -/* get_file_length - * Return the length of a file, in bytes. In case of error, returns ~0. - */ -static uword -get_file_length(int fd) -{ - off_t here; - off_t eof; - - /* Get the current position within the file */ - here = lseek(fd, 0L, SEEK_CUR); - if (here < 0) - /* The file isn't seekable, presumably either because it - * isn't open, or because it's a pipe/socket/FIFO/tty. - */ - return ~0; - - /* Go to the end of the file */ - eof = lseek(fd, 0L, SEEK_END); - - /* And return to where we were before */ - lseek(fd, here, SEEK_SET); - - return (uword) (eof - here); -} - -/* pdb_LoadHeader - * Read the header of a pdb file, and fill in the appropriate fields in - * 'db'. - */ -int -pdb_LoadHeader(int fd, - struct pdb *db) -{ - int err; - static ubyte buf[PDB_HEADER_LEN]; - /* Buffer to hold the file header */ - const ubyte *rptr; /* Pointer into buffers, for reading */ - - /* Read the header */ - if ((err = read(fd, buf, PDB_HEADER_LEN)) != PDB_HEADER_LEN) - { - perror("pdb_LoadHeader: read"); - return -1; - } - - /* Parse the database header */ - rptr = buf; - memcpy(db->name, buf, PDB_DBNAMELEN); - rptr += PDB_DBNAMELEN; - db->attributes = get_uword(&rptr); - db->version = get_uword(&rptr); - db->ctime = get_udword(&rptr); - db->mtime = get_udword(&rptr); - db->baktime = get_udword(&rptr); - db->modnum = get_udword(&rptr); - db->appinfo_offset = get_udword(&rptr); - db->sortinfo_offset = get_udword(&rptr); - db->type = get_udword(&rptr); - db->creator = get_udword(&rptr); - db->uniqueIDseed = get_udword(&rptr); - - PDB_TRACE(5) - { - time_t t; - - fprintf(stderr, "\tname: \"%s\"\n", db->name); - fprintf(stderr, "\tattributes: 0x%04x", db->attributes); - if (db->attributes & PDB_ATTR_RESDB) - fprintf(stderr, " RESDB"); - if (db->attributes & PDB_ATTR_RO) fprintf(stderr, " RO"); - if (db->attributes & PDB_ATTR_APPINFODIRTY) - fprintf(stderr, " APPINFODIRTY"); - if (db->attributes & PDB_ATTR_BACKUP) - fprintf(stderr, " BACKUP"); - if (db->attributes & PDB_ATTR_OKNEWER) - fprintf(stderr, " OKNEWER"); - if (db->attributes & PDB_ATTR_RESET) fprintf(stderr, " RESET"); - if (db->attributes & PDB_ATTR_NOCOPY) - fprintf(stderr, " NOCOPY"); - if (db->attributes & PDB_ATTR_STREAM) - fprintf(stderr, " STREAM"); - if (db->attributes & PDB_ATTR_OPEN) - fprintf(stderr, " OPEN"); - fprintf(stderr, "\n"); - fprintf(stderr, "\tversion: %u\n", db->version); - t = db->ctime - EPOCH_1904; - fprintf(stderr, "\tctime: %lu %s", (unsigned long) db->ctime, - ctime(&t)); - t = db->mtime - EPOCH_1904; - fprintf(stderr, "\tmtime: %lu %s", (unsigned long) db->mtime, - ctime(&t)); - t = db->baktime - EPOCH_1904; - fprintf(stderr, "\tbaktime: %lu %s", (unsigned long) db->baktime, - ctime(&t)); - fprintf(stderr, "\tmodnum: %lu\n", (unsigned long) db->modnum); - fprintf(stderr, "\tappinfo_offset: 0x%08lx\n", - (unsigned long) db->appinfo_offset); - fprintf(stderr, "\tsortinfo_offset: 0x%08lx\n", - (unsigned long) db->sortinfo_offset); - fprintf(stderr, "\ttype: '%c%c%c%c' (0x%08lx)\n", - (char) (db->type >> 24) & 0xff, - (char) (db->type >> 16) & 0xff, - (char) (db->type >> 8) & 0xff, - (char) db->type & 0xff, - (unsigned long) db->type); - fprintf(stderr, "\tcreator: '%c%c%c%c' (0x%08lx)\n", - (char) (db->creator >> 24) & 0xff, - (char) (db->creator >> 16) & 0xff, - (char) (db->creator >> 8) & 0xff, - (char) db->creator & 0xff, - (unsigned long) db->creator); - fprintf(stderr, "\tuniqueIDseed: %lu\n", - (unsigned long) db->uniqueIDseed); - } - - return 0; /* Success */ -} - -/* pdb_LoadRecListHeader - * Load the record list header from a pdb file, and fill in the appropriate - * fields in 'db'. - */ -static int -pdb_LoadRecListHeader(int fd, - struct pdb *db) -{ - int err; - static ubyte buf[PDB_RECORDLIST_LEN]; - const ubyte *rptr; /* Pointer into buffers, for reading */ - - /* Read the record list header */ - if ((err = read(fd, buf, PDB_RECORDLIST_LEN)) != PDB_RECORDLIST_LEN) - { - perror("pdb_LoadRecListHeader: read2"); - return -1; - } - - /* Parse the record list */ - rptr = buf; - db->next_reclistID = get_udword(&rptr); - db->numrecs = get_uword(&rptr); - - PDB_TRACE(6) - { - fprintf(stderr, "\tnextID: %ld\n", (long) db->next_reclistID); - fprintf(stderr, "\tlen: %u\n", db->numrecs); - } - - return 0; -} - -/* pdb_LoadRsrcIndex - * Read the resource index from a resource database file, and fill in the - * appropriate fields in 'db'. - */ -static int -pdb_LoadRsrcIndex(int fd, - struct pdb *db) -{ - int i; - int err; - uword totalrsrcs; /* The real number of resources in the - * database. - */ - - totalrsrcs = db->numrecs; /* Get the number of resources in - * the database. It is necessary to - * remember this here because - * pdb_AppendResource() increments - * db->numrecs in the name of - * convenience. - */ - - if (totalrsrcs == 0) - { - /* There are no resources in this file */ - db->rec_index.rsrc = NULL; - return 0; - } - - /* Read the resource index */ - for (i = 0; i < totalrsrcs; i++) - { - static ubyte inbuf[PDB_RESOURCEIX_LEN]; - /* Input buffer */ - const ubyte *rptr; /* Pointer into buffers, for reading */ - struct pdb_resource *rsrc; - /* New resource entry */ - - /* Allocate the resource entry */ - if ((rsrc = (struct pdb_resource *) - malloc(sizeof(struct pdb_resource))) - == NULL) - return -1; - /* Scribble zeros all over it, just in case */ - memset((void *) rsrc, 0, sizeof(struct pdb_resource)); - - /* Read the next resource index entry */ - if ((err = read(fd, inbuf, PDB_RESOURCEIX_LEN)) != - PDB_RESOURCEIX_LEN) - return -1; - - /* Parse it */ - rptr = inbuf; - rsrc->type = get_udword(&rptr); - rsrc->id = get_uword(&rptr); - rsrc->offset = get_udword(&rptr); - - PDB_TRACE(6) - { - fprintf(stderr, - "\tResource %d: type '%c%c%c%c' (0x%08lx), " - "id %u, offset 0x%08lx\n", - i, - (char) (rsrc->type >> 24) & 0xff, - (char) (rsrc->type >> 16) & 0xff, - (char) (rsrc->type >> 8) & 0xff, - (char) rsrc->type & 0xff, - (unsigned long) rsrc->type, - rsrc->id, - (unsigned long) rsrc->offset); - } - - /* Append the new resource to the list */ - pdb_AppendResource(db, rsrc); /* XXX - Error-checking */ - db->numrecs = totalrsrcs; /* Kludge */ - } - - return 0; -} - -/* pdb_LoadRecIndex - * Read the record index from a record database file, and fill in the - * appropriate fields in 'db'. - */ -static int -pdb_LoadRecIndex(int fd, - struct pdb *db) -{ - int i; - int err; - uword totalrecs; /* The real number of records in the - * database. - */ - - totalrecs = db->numrecs; /* Get the number of records in the - * database. It is necessary to - * remember this here because - * pdb_AppendResource() increments - * db->numrecs in the name of - * convenience. - */ - - if (totalrecs == 0) - { - /* There are no records in this file */ - db->rec_index.rec = NULL; - return 0; - } - - /* Read the record index */ - /* XXX - It would be a Good Thing to check for zero-length records - * here. They've been known to appear as a result of a broken - * conduit. - */ - for (i = 0; i < totalrecs; i++) - { - static ubyte inbuf[PDB_RECORDIX_LEN]; - /* Input buffer */ - const ubyte *rptr; /* Pointer into buffers, for reading */ - struct pdb_record *rec; - /* New record entry */ - ubyte attributes; /* Combined flags+category field */ - - /* Allocate the record entry */ - if ((rec = (struct pdb_record *) - malloc(sizeof(struct pdb_record))) - == NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "pdb_LoadRecIndex"); - return -1; - } - - /* Scribble zeros all over it, just in case */ - memset((void *) rec, 0, sizeof(struct pdb_record)); - - /* Read the next record index entry */ - if ((err = read(fd, inbuf, PDB_RECORDIX_LEN)) != - PDB_RECORDIX_LEN) - { - fprintf(stderr, _("%s: error reading record index " - "entry for \"%.*s\" (%d bytes): " - "%d.\n"), - "LoadRecIndex", - PDB_DBNAMELEN, db->name, - PDB_RECORDIX_LEN, - err); - perror("read"); - free(rec); - return -1; - } - - /* Parse it */ - rptr = inbuf; - rec->offset = get_udword(&rptr); - attributes = get_ubyte(&rptr); - split_attributes(attributes, &(rec->flags), &(rec->category)); - - rec->id = - ((udword) (get_ubyte(&rptr) << 16)) | - ((udword) (get_ubyte(&rptr) << 8)) | - ((udword) get_ubyte(&rptr)); - - PDB_TRACE(6) - fprintf(stderr, - "\tRecord %d: offset 0x%08lx, flags 0x%02x, " - " category 0x%02x, ID 0x%08lx\n", - i, - (unsigned long) rec->offset, - (unsigned) rec->flags, - rec->category, - (unsigned long) rec->id); - - /* Append the new record to the database */ - pdb_AppendRecord(db, rec); /* XXX - Error-checking */ - db->numrecs = totalrecs; /* Kludge */ - } - - return 0; -} - -/* pdb_LoadAppBlock - * Read the AppInfo block from a database file, and fill in the appropriate - * fields in 'db'. If the file doesn't have an AppInfo block, set it to - * NULL. - */ -static int -pdb_LoadAppBlock(int fd, - struct pdb *db) -{ - int err; - udword next_off; /* Offset of the next thing in the file - * after the AppInfo block */ - off_t offset; /* Offset into file, for checking */ - - /* Check to see if there even *is* an AppInfo block */ - if (db->appinfo_offset == 0L) - { - /* Nope */ - db->appinfo_len = 0L; - db->appinfo = NULL; - return 0; - } - - /* Figure out how long the AppInfo block is, by comparing its - * offset to that of the next thing in the file. - */ - if (db->sortinfo_offset > 0L) - /* There's a sort block */ - next_off = db->sortinfo_offset; - else if (db->numrecs > 0) - { - /* There's no sort block, but there are records. Get the - * offset of the first one. - */ - if (IS_RSRC_DB(db)) - next_off = db->rec_index.rsrc->offset; - else - next_off = db->rec_index.rec->offset; - } else - /* There is neither sort block nor records, so the AppInfo - * block must go to the end of the file. - */ - next_off = db->file_size; - - /* Subtract the AppInfo block's offset from that of the next thing - * in the file to get the AppInfo block's length. - */ - db->appinfo_len = next_off - db->appinfo_offset; - - /* This is probably paranoid, but what the hell */ - if (db->appinfo_len == 0L) - { - /* An effective no-op */ - db->appinfo = NULL; - return 0; - } - - /* Now that we know the length of the AppInfo block, allocate space - * for it and read it. - */ - if ((db->appinfo = (ubyte *) malloc(db->appinfo_len)) == NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "pdb_LoadAppBlock"); - return -1; - } - - /* Just out of paranoia, make sure we're at the correct offset in - * the file. Since the two NULs may or may not have appeared in the - * file, the only thing that it makes sense to check is whether - * we've already passed the beginning of the AppInfo block, as - * given by its offset in the header. - */ - offset = lseek(fd, 0L, SEEK_CUR); /* Find out where we are */ - if (offset != db->appinfo_offset) - { - if (offset > (off_t) db->appinfo_offset) - { - /* Oops! We're in the wrong place */ - fprintf(stderr, _("Warning: AppInfo block in \"%.*s\" " - "isn't where I thought it would " - "be.\n" - "Expected 0x%lx, but we're at " - "0x%lx.\n"), - PDB_DBNAMELEN, db->name, - (unsigned long) db->appinfo_offset, (unsigned long) offset); - } - - /* Try to recover */ - offset = lseek(fd, db->appinfo_offset, SEEK_SET); - /* Go to where the AppInfo block - * ought to be */ - if (offset < 0) - { - /* Something's wrong */ - fprintf(stderr, _("Can't find the AppInfo block in " - "\"%.*s\"!\n"), - PDB_DBNAMELEN, db->name); - return -1; - } - } - - /* Read the AppInfo block */ - if ((err = read(fd, db->appinfo, db->appinfo_len)) != db->appinfo_len) - { - perror("pdb_LoadAppBlock: read"); - return -1; - } - PDB_TRACE(6) - debug_dump(stderr, "appinfo, db->appinfo_len); - - return 0; -} - -/* pdb_LoadSortBlock - * Read the sort block from a database file, and fill in the appropriate - * fields in 'db'. If the file doesn't have a sort block, set it to NULL. - * - * XXX - Largely untested, since not that many databases have sort blocks. - * But it's basically just a clone of pdb_LoadAppBlock(), so it should be - * okay. - */ -static int -pdb_LoadSortBlock(int fd, - struct pdb *db) -{ - int err; - localID next_off; /* Offset of the next thing in the file - * after the sort block */ - off_t offset; /* Offset into file, for checking */ - - /* Check to see if there even *is* a sort block */ - if (db->sortinfo_offset == 0L) - { - /* Nope */ - db->sortinfo_len = 0L; - db->sortinfo = NULL; - return 0; - } - - /* Figure out how long the sort block is, by comparing its - * offset to that of the next thing in the file. - */ - if (db->numrecs > 0) - { - /* There are records. Get the offset of the first one. - */ - if (IS_RSRC_DB(db)) - next_off = db->rec_index.rsrc->offset; - else - next_off = db->rec_index.rec->offset; - } else - /* There are no records, so the sort block must go to the - * end of the file. - */ - next_off = db->file_size; - - /* Subtract the sort block's offset from that of the next thing - * in the file to get the sort block's length. - */ - db->sortinfo_len = next_off - db->sortinfo_offset; - - /* This is probably paranoid, but what the hell */ - if (db->sortinfo_len == 0L) - { - /* An effective no-op */ - db->sortinfo = NULL; - return 0; - } - - /* Now that we know the length of the sort block, allocate space - * for it and read it. - */ - if ((db->sortinfo = (ubyte *) malloc(db->sortinfo_len)) == NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "pdb_LoadSortBlock"); - return -1; - } - - /* Just out of paranoia, make sure we're at the correct offset in - * the file. Since the two NULs may or may not have appeared in the - * file, the only thing that it makes sense to check is whether - * we've already passed the beginning of the sort block, as given - * by its offset in the header. - */ - offset = lseek(fd, 0L, SEEK_CUR); /* Find out where we are */ - if (offset != db->sortinfo_offset) - { - if (offset > (off_t) db->sortinfo_offset) - { - /* Oops! We're in the wrong place */ - fprintf(stderr, _("Warning: sort block in \"%.*s\" " - "isn't where I thought it would " - "be.\n" - "Expected 0x%lx, but we're at " - "0x%lx.\n"), - PDB_DBNAMELEN, db->name, - (unsigned long) db->sortinfo_offset, - (unsigned long) offset); - } - - /* Try to recover */ - offset = lseek(fd, db->sortinfo_offset, SEEK_SET); - /* Go to where the sort block - * ought to be */ - if (offset < 0) - { - /* Something's wrong */ - fprintf(stderr, _("Can't find the sort block in " - "\"%.*s\"!\n"), - PDB_DBNAMELEN, db->name); - return -1; - } - } - - /* Read the sort block */ - if ((err = read(fd, db->sortinfo, db->sortinfo_len)) != - db->sortinfo_len) - { - perror("pdb_LoadSortBlock: read"); - return -1; - } - PDB_TRACE(6) - debug_dump(stderr, "sortinfo, db->sortinfo_len); - - return 0; -} - -/* pdb_LoadResources - * Read each resource in turn from a resource database file. - */ -static int -pdb_LoadResources(int fd, - struct pdb *db) -{ - int i; - int err; - struct pdb_resource *rsrc; - - /* This assumes that the resource list has already been created by - * 'pdb_LoadRsrcIndex()'. - */ - for (i = 0, rsrc = db->rec_index.rsrc; - i < db->numrecs; - i++, rsrc = rsrc->next) - { - off_t offset; /* Current offset, for checking */ - udword next_off; /* Offset of next resource in file */ - - /* Sanity check: make sure we haven't stepped off the end - * of the list. - */ - if (rsrc == NULL) - { - fprintf(stderr, _("Hey! I can't find the %dth " - "resource in \"%.*s\"!\n"), - i, - PDB_DBNAMELEN, db->name); - return -1; - } - - PDB_TRACE(5) - fprintf(stderr, - "Reading resource %d (type '%c%c%c%c')\n", - i, - (char) (rsrc->type >> 24) & 0xff, - (char) (rsrc->type >> 16) & 0xff, - (char) (rsrc->type >> 8) & 0xff, - (char) rsrc->type & 0xff); - - /* Out of paranoia, make sure we're in the right place. - * Since the two NULs may or may not have appeared in the - * file, the only thing that it makes sense to check is - * whether we've already passed the beginning of the - * resource, as given by its offset in the resource index. - */ - offset = lseek(fd, 0L, SEEK_CUR); - /* Find out where we are now */ - if (offset != rsrc->offset) - { - if (offset > (off_t) rsrc->offset) - { - fprintf(stderr, _("Warning: resource %d in " - "\"%.*s\" isn't where " - "I thought it would be.\n" - "Expected 0x%lx, but we're " - "at 0x%lx.\n"), - i, - PDB_DBNAMELEN, db->name, - (unsigned long) rsrc->offset, - (unsigned long) offset); - } - - /* Try to recover */ - offset = lseek(fd, rsrc->offset, SEEK_SET); - /* Go to where this - * resource ought to be. - */ - if (offset < 0) - { - /* Something's wrong */ - fprintf(stderr, _("Can't find resource %d in " - "\"%.*s\".\n"), - i, - PDB_DBNAMELEN, db->name); - return -1; - } - } - - /* Okay, now that we're in the right place, find out what - * the next thing in the file is: its offset will tell us - * how much to read. - * It's debatable whether 'i' or 'rsrc' should be - * authoritative for determining the offset of the next - * resource. I'm going to choose 'rsrc', since I think - * that's more likely to be immune to fencepost errors. The - * two should, however, be equivalent. In fact, it might be - * a Good Thing to add a check to make sure. - */ - if (rsrc->next == NULL) - { - /* This is the last resource in the file, so it - * goes to the end of the file. - */ - next_off = db->file_size; - } else { - /* This isn't the last resource. Find the next - * one's offset. - */ - next_off = rsrc->next->offset; - } - - /* Subtract this resource's index from that of the next - * thing, to get the size of this resource. - */ - rsrc->data_len = (uword) (next_off - rsrc->offset); - - /* Allocate space for this resource */ - if ((rsrc->data = (ubyte *) malloc(rsrc->data_len)) == NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "pdb_LoadResources"); - return -1; - } - - /* Read the resource */ - if ((err = read(fd, rsrc->data, rsrc->data_len)) != - rsrc->data_len) - { - fprintf(stderr, _("Can't read resource %d in " - "\"%.*s\".\n"), - i, - PDB_DBNAMELEN, db->name); - perror("pdb_LoadResources: read"); - return -1; - } - PDB_TRACE(6) - { - fprintf(stderr, "Contents of resource %d:\n", i); - debug_dump(stderr, "data, - rsrc->data_len); - } - } - - return 0; /* Success */ -} - -/* pdb_LoadRecords - * Read each record in turn from a record database file. - */ -static int -pdb_LoadRecords(int fd, - struct pdb *db) -{ - int i; - int err; - struct pdb_record *rec; - - /* This assumes that the record list has already been created by - * 'pdb_LoadRecIndex()'. - */ - for (i = 0, rec = db->rec_index.rec; - i < db->numrecs; - i++, rec = rec->next) - { - off_t offset; /* Current offset, for checking */ - localID next_off; /* Offset of next resource in file */ - - /* Sanity check: make sure we haven't stepped off the end - * of the list. - */ - if (rec == NULL) - { - fprintf(stderr, _("Hey! I can't find the %dth " - "record in \"%.*s\"!\n"), - i, - PDB_DBNAMELEN, db->name); - return -1; - } - - PDB_TRACE(5) - fprintf(stderr, "Reading record %d (id 0x%08lx)\n", - i, (unsigned long) rec->id); - - /* Out of paranoia, make sure we're in the right place. - * Since the two NULs may or may not have appeared in the - * file, the only thing that it makes sense to check is - * whether we've already passed the beginning of the - * record, as given by its offset in the record index. - */ - offset = lseek(fd, 0L, SEEK_CUR); - /* Find out where we are now */ - if (offset != rec->offset) - { - if (offset > (off_t) rec->offset) - { - fprintf(stderr, _("Warning: record %d in " - "\"%.*s\" isn't where " - "I thought it would be.\n" - "Expected 0x%lx, but we're " - "at 0x%lx.\n"), - i, - PDB_DBNAMELEN, db->name, - (unsigned long) rec->offset, - (unsigned long) offset); - } - - /* Try to recover */ - offset = lseek(fd, rec->offset, SEEK_SET); - /* Go to where this record - * ought to be. */ - if (offset < 0) - { - /* Something's wrong */ - fprintf(stderr, _("Can't find record %d in " - "\"%.*s\".\n"), - i, - PDB_DBNAMELEN, db->name); - return -1; - } - } - - /* Okay, now that we're in the right place, find out what - * the next thing in the file is: its offset will tell us - * how much to read. - * It's debatable whether 'i' or 'rec' should be - * authoritative for determining the offset of the next - * resource. I'm going to choose 'rec', since I think - * that's more likely to be immune from fencepost errors. - * The two should, however, be equivalent. In fact, it - * might be a Good Thing to add a check to make sure. - */ - if (rec->next == NULL) - { - /* This is the last record in the file, so it goes - * to the end of the file. - */ - next_off = db->file_size; - } else { - /* This isn't the last record. Find the next one's - * offset. - */ - next_off = rec->next->offset; - } - - /* Subtract this record's index from that of the next one, - * to get the size of this record. - */ - rec->data_len = (uword) (next_off - rec->offset); - - /* Allocate space for this record - * If there's a record with length zero, don't pass that to - * malloc(). This is most likely due to a broken conduit. - * XXX - The Right Thing to do would be not to read - * zero-length records, but that would involve fixing the - * record index. - */ - if (rec->data_len > 0) - { - if ((rec->data = (ubyte *) malloc(rec->data_len)) == - NULL) - { - fprintf(stderr, _("%s: Out of memory.\n"), - "pdb_LoadRecords"); - return -1; - } - - /* Read the record */ - if ((err = read(fd, rec->data, rec->data_len)) != - rec->data_len) - { - fprintf(stderr, _("Can't read record %d in " - "\"%.*s\".\n"), - i, - PDB_DBNAMELEN, db->name); - perror("pdb_LoadRecords: read"); - return -1; - } - - PDB_TRACE(6) - { - fprintf(stderr, "Contents of record %d:\n", i); - debug_dump(stderr, "data, - rec->data_len); - } - } - } - - return 0; /* Success */ -} - - /* This is for Emacs's benefit: - * Local Variables: *** - * fill-column: 75 *** - * End: *** - */ -#endif /* PDBFMTS_DISABLED */ diff --git a/coldsync/pdb.h b/coldsync/pdb.h deleted file mode 100644 index 1d34d23c4..000000000 --- a/coldsync/pdb.h +++ /dev/null @@ -1,273 +0,0 @@ -/* pdb.h - * - * Definitions and such for Palm databases. - * - * Copyright (C) 1999-2000, Andrew Arensburger. - * You may distribute this file under the terms of the Artistic - * License, as specified in the README file. - * - * $Id: pdb.h,v 1.1 2002/08/16 06:13:10 robertl Exp $ - */ -#ifndef _pdb_h_ -#define _pdb_h_ - -/* XXX - Add a type (and support functions) for those ubitquitous - * 4-character IDs. - */ - -#define EPOCH_1904 2082844800L /* Difference, in seconds, between - * Palm's epoch (Jan. 1, 1904) and - * Unix's epoch (Jan. 1, 1970). - */ - -#define PDB_DBNAMELEN 32 /* Length of name field in database - * header */ - -/* Database attribute flags */ -#define PDB_ATTR_RESDB 0x0001 /* This is a resource database. - * Resource databases are usually - * saved in files with ".prc" - * extensions. Other databases are - * saved with a ".pdb" extension. - */ -#define PDB_ATTR_RO 0x0002 /* Read-only database */ -#define PDB_ATTR_APPINFODIRTY 0x0004 /* App info block is dirty */ -#define PDB_ATTR_BACKUP 0x0008 /* Back up the database if no - * app-specific conduit exists */ -#define PDB_ATTR_OKNEWER 0x0010 /* Tells the backup conduit that - * it's okay to install a newer - * version of this database with a - * different name if this one is - * open. Usually used for the - * Graffiti Shortcuts database. - */ -#define PDB_ATTR_RESET 0x0020 /* Reset the Palm after the - * database is installed */ -#define PDB_ATTR_NOCOPY 0x0040 /* Database should not be copied(?) */ -#define PDB_ATTR_STREAM 0x0080 /* Database is used for file stream - * implementation(?). - */ -#define PDB_ATTR_OPEN 0x8000 /* Database is open */ - -/* Record attributes - * These are the attributes that individual records in a database can have. - * I've taken the liberty of giving them different names from Palm's, since - * Palm's names are rather confusing. - * - * PDB_REC_PRIVATE is set on a record that has been marked "private" by the - * user. It is not encrypted, and if the desktop asks for this record, the - * Palm will not refuse or ask for a password. In short, the Palm needs to - * trust the desktop. - * - * PDB_REC_DIRTY is set on a record whose contents have been modified since - * the last sync. If the user deletes a record without modifying it, - * PDB_REC_DIRTY will not be set, but if he modifies it, then deletes it, - * then both PDB_REC_DIRTY and PDB_REC_DELETED will be set. - * - * PDB_REC_DELETED is set on a record that has been deleted by the user - * since the last sync. Unfortunately, it looks as if not all applications - * are polite enough to set this flag, so you have to go with - * PDB_REC_ARCHIVE and PDB_REC_EXPUNGED. - * - * If the user chose the "Save archive copy on PC" option when deleting a - * record, then the PDB_REC_ARCHIVE bit will be set on the record (with any - * luck, so will PDB_REC_DELETED). - * - * If the user did not choose the "Save archive copy on PC" option when - * deleting a record, the PDB_REC_EXPUNGED bit will be set on the record - * (as will PDB_REC_DELETED, perhaps). Apparently, what happens is this: - * when the user deletes a record, a copy is left around so that HotSync - * will know to delete this record. However, if the user chose not to keep - * a copy, then, in order to conserve memory, the Palm will delete the - * record data, although it will keep a copy of the record header for - * HotSync. - */ -#define PDB_REC_EXPUNGED 0x80 /* The contents of this record have - * been deleted, leaving only the - * record info. (Palm calls this - * 'dlpRecAttrDeleted'.) - */ -#define PDB_REC_DIRTY 0x40 /* Record has been modified. (Palm - * calls this 'dlpRecAttrDirty'.) - */ -#define PDB_REC_DELETED 0x20 /* This record has been deleted. - * (Palm calls this - * 'dlpRecAttrBusy'.) - */ -#define PDB_REC_PRIVATE 0x10 /* Record is private: don't show to - * anyone without asking for a - * password. (Palm calls this - * 'dlpRecAttrSecret'.) - */ -#define PDB_REC_ARCHIVE 0x08 /* This record should be archived - * at the next sync. (Palm calls - * this 'dlpRecAttrArchived'.) - */ - -typedef udword localID; /* Local (card-relative) chunk ID - * (basically, a pointer that can - * be used as a unique ID). - */ - -#define PDB_HEADER_LEN 72 /* Length of header in a file */ -#define PDB_RECORDLIST_LEN 6 /* Length of record index header in - * file */ - -/* pdb_record - * A plain old record, containing arbitrary data. - */ -struct pdb_record -{ - struct pdb_record *next; /* Next record on linked list */ - localID offset; /* Offset of record in file */ - ubyte flags; /* Record flags (PDB_REC_*) */ - ubyte category; /* Record's category */ - udword id; /* Record's unique ID. Actually, - * only the bottom 3 bytes are - * stored in the file, but for - * everything else, it's much - * easier to just consider this a - * 32-bit integer. - */ - uword data_len; /* Length of this record */ - ubyte *data; /* This record's data */ -}; -#define PDB_RECORDIX_LEN 8 /* Size of a pdb_record in a file */ - -/* pdb_resource - * Mac hackers should feel at home here: the type of a resource is really a - * 4-character category identifier, and the ID is an integer within that - * category. - */ -struct pdb_resource -{ - struct pdb_resource *next; /* Next resource on linked list */ - udword type; /* Resource type */ - uword id; /* Resource ID */ - localID offset; /* Offset of resource in file */ - uword data_len; /* Length of this resource */ - ubyte *data; /* This resource's data */ -}; -#define PDB_RESOURCEIX_LEN 10 /* Size of a pdb_resource in a file */ - -/* pdb - * Structure of a Palm database (file), both resource databases (.prc) and - * record databases (.pdb). - */ -struct pdb -{ - long file_size; /* Total length of file */ - - char name[PDB_DBNAMELEN]; /* Database name */ - uword attributes; /* Database attributes */ - uword version; /* Database version */ - - udword ctime; /* Creation time */ - udword mtime; /* Time of last modification */ - udword baktime; /* Time of last backup */ - udword modnum; /* Modification number */ - /* XXX - What exactly is the modification number? - * Does it get incremented each time you make any - * kind of change to the database? - */ - localID appinfo_offset; /* Offset of AppInfo block in the - * file */ - localID sortinfo_offset; /* Offset of sort block in the file */ - - udword type; /* Database type */ - udword creator; /* Database creator */ - - udword uniqueIDseed; /* Used to generate unique IDs for - * records and resources. Only the - * lower 3 bytes are used. The high - * byte is for alignment. - */ - - localID next_reclistID; /* ID of next record index in the - * file. In practice, this field is - * always zero. - */ - uword numrecs; /* Number of records/resources in - * the file. - */ - - long appinfo_len; /* Length of AppInfo block */ - void *appinfo; /* Optional AppInfo block */ - long sortinfo_len; /* Length of sort block */ - void *sortinfo; /* Optional sort block */ - - /* Record/resource list. Each of these is actually a linked list, - * to make it easy to insert and delete records. - */ - union { - struct pdb_record *rec; - struct pdb_resource *rsrc; - } rec_index; -}; - -/* Convenience macros */ -#define IS_RSRC_DB(db) ((db)->attributes & PDB_ATTR_RESDB) - /* Is this a resource database? If - * not, it must be a record - * database. - */ - -extern int pdb_trace; /* Debugging level for PDB stuff */ - -extern struct pdb *new_pdb(); -extern void free_pdb(struct pdb *db); -extern void pdb_FreeRecord(struct pdb_record *rec); -extern void pdb_FreeResource(struct pdb_resource *rsrc); -extern struct pdb *pdb_Read(int fd); /* Load a pdb from a file. */ -extern int pdb_Write(const struct pdb *db, int fd); - /* Write a pdb to a file */ -extern struct pdb_record *pdb_FindRecordByID( - const struct pdb *db, - const udword id); -extern struct pdb_record *pdb_FindRecordByIndex( - const struct pdb *db, - const uword index); -extern int pdb_DeleteRecordByID( - struct pdb *db, - const udword id); -extern int pdb_AppendRecord(struct pdb *db, struct pdb_record *newrec); -extern int pdb_AppendResource(struct pdb *db, struct pdb_resource *newrsrc); -extern int pdb_InsertRecord( - struct pdb *db, - struct pdb_record *prev, - struct pdb_record *newrec); -extern int pdb_InsertResource( - struct pdb *db, - struct pdb_resource *prev, - struct pdb_resource *newrsrc); -extern struct pdb_record *new_Record( - const ubyte attributes, - const ubyte category, - const udword id, - const uword len, - const ubyte *data); -extern struct pdb_resource *new_Resource( - const udword type, - const uword id, - const uword len, - const ubyte *data); -extern struct pdb_record *pdb_CopyRecord( - const struct pdb *db, - const struct pdb_record *rec); -extern struct pdb_resource *pdb_CopyResource( - const struct pdb *db, - const struct pdb_resource *rsrc); -extern int pdb_LoadHeader(int fd, struct pdb *db); - -/* XXX - Functions to write: -pdb_setAppInfo set the appinfo block -pdb_setSortInfo set the sortinfo block -*/ - -#endif /* _pdb_h_ */ - - /* This is for Emacs's benefit: - * Local Variables: *** - * fill-column: 75 *** - * End: *** - */ diff --git a/coldsync/util.c b/coldsync/util.c deleted file mode 100644 index 3afb545d7..000000000 --- a/coldsync/util.c +++ /dev/null @@ -1,293 +0,0 @@ -/* util.c - * - * Misc. utility functions. - * - * Copyright (C) 1999, Andrew Arensburger. - * You may distribute this file under the terms of the Artistic - * License, as specified in the README file. - * - * The get_*() functions are used to extract values out of strings of - * ubytes and convert them to the native format. - * The put_*() functions, conversely, are used to take a value in the - * native format, convert them to Palm (big-endian) format, and write - * them to a ubyte string. - * - * $Id: util.c,v 1.6 2006/05/07 02:14:35 robertl Exp $ - */ - -#include "config.h" -#include "cs-config.h" -#if PDBFMTS_ENABLED -#include -#include /* For isprint() */ -#include - -#ifndef EPOCH_1904 -# define EPOCH_1904 2082844800L /* Difference, in seconds, between - * Palm's epoch (Jan. 1, 1904) and - * Unix's epoch (Jan. 1, 1970). - */ -#endif /* EPOCH_1904 */ - -/* XXX - Most of the functions below really ought to be inlined. Not sure - * how to do this portably, though. - */ - -INLINE ubyte -peek_ubyte(const ubyte *buf) -{ - return buf[0]; -} - -INLINE uword -peek_uword(const ubyte *buf) -{ - return ((uword) buf[0] << 8) | - buf[1]; -} - -INLINE udword -peek_udword(const ubyte *buf) -{ - return ((uword) buf[0] << 24) | - ((uword) buf[1] << 16) | - ((uword) buf[2] << 8) | - buf[3]; -} - -INLINE ubyte -get_ubyte(const ubyte **buf) -{ - ubyte retval; - - retval = peek_ubyte(*buf); - *buf += SIZEOF_UBYTE; - - return retval; -} - -INLINE void -put_ubyte(ubyte **buf, const ubyte value) -{ - **buf = value; - ++(*buf); -} - -INLINE uword -get_uword(const ubyte **buf) -{ - uword retval; - - retval = peek_uword(*buf); - *buf += SIZEOF_UWORD; - - return retval; -} - -INLINE void -put_uword(ubyte **buf, const uword value) -{ - **buf = (value >> 8) & 0xff; - ++(*buf); - **buf = value & 0xff; - ++(*buf); -} - -INLINE udword -get_udword(const ubyte **buf) -{ - udword retval; - - retval = peek_udword(*buf); - *buf += SIZEOF_UDWORD; - - return retval; -} - -INLINE void -put_udword(ubyte **buf, const udword value) -{ - **buf = (ubyte) ((value >> 24) & 0xff); - ++(*buf); - **buf = (ubyte) ((value >> 16) & 0xff); - ++(*buf); - **buf = (ubyte) ((value >> 8) & 0xff); - ++(*buf); - **buf = (ubyte) (value & 0xff); - ++(*buf); -} -#if TIME -/* XXX - Figure out the timezone hairiness: - * Palms don't have timezones. Hence, the Palm's epoch is Jan. 1, 1904 in - * the local timezone. - * Unless you're syncing across the network, in which case its epoch is - * Jan. 1, 1904 in the timezone it happens to be in (which may not be the - * same as the desktop's timezone). - * Except that there are (I'm sure) tools that add timezones to the Palm. - * These should be consulted. - * Times generated locally are in the local timezone (i.e., the one that - * the desktop machine is in). - */ - -/* time_dlp2time_t - * Convert the DLP time structure into a Unix time_t, and return it. - */ -time_t -time_dlp2time_t(const struct dlp_time *dlpt) -{ - struct tm tm; - - /* Convert the dlp_time into a struct tm, then just use mktime() to - * do the conversion. - */ - tm.tm_sec = dlpt->second; - tm.tm_min = dlpt->minute; - tm.tm_hour = dlpt->hour; - tm.tm_mday = dlpt->day; - tm.tm_mon = dlpt->month - 1; - tm.tm_year = dlpt->year - 1900; - tm.tm_wday = 0; - tm.tm_yday = 0; - tm.tm_isdst = 0; -#if HAVE_TM_ZONE - tm.tm_gmtoff = 0; - tm.tm_zone = NULL; -#else -/* XXX - ANSI doesn't allow #warning, and we're not using the timezone for - * anything yet. - */ -/* #warning You do not have tm_zone */ -#endif - - return mktime(&tm); -} - -/* time_dlp2palmtime - * Convert a DLP time structure into a Palm time_t (number of seconds since - * Jan. 1. 1904), and return it. - */ -udword -time_dlp2palmtime(const struct dlp_time *dlpt) -{ - time_t now; /* The time, as a Unix time_t */ - struct tm tm; - - /* Convert the dlp_time into a struct tm, use mktime() to do the - * conversion, and add the difference in epochs. - */ - tm.tm_sec = dlpt->second; - tm.tm_min = dlpt->minute; - tm.tm_hour = dlpt->hour; - tm.tm_mday = dlpt->day; - tm.tm_mon = dlpt->month - 1; - tm.tm_year = dlpt->year - 1900; - tm.tm_wday = 0; - tm.tm_yday = 0; - tm.tm_isdst = 0; -#if HAVE_TM_ZONE - tm.tm_gmtoff = 0; - tm.tm_zone = NULL; -#endif - - now = mktime(&tm); - now += EPOCH_1904; - - return now; -} - -/* time_time_t2dlp - * Convert a Unix time_t into a DLP time structure. Put the result in - * 'dlpt'. - */ -void -time_time_t2dlp(const time_t t, - struct dlp_time *dlpt) -{ - struct tm *tm; - - tm = localtime(&t); /* Break 't' down into components */ - - /* Copy the relevant fields over to 'dlpt' */ - dlpt->year = tm->tm_year + 1900; - dlpt->month = tm->tm_mon + 1; - dlpt->day = tm->tm_mday; - dlpt->hour = tm->tm_hour; - dlpt->minute = tm->tm_min; - dlpt->second = tm->tm_sec; -} - -/* time_palmtime2dlp - - * Convert a Palm time (seconds since the Jan. 1, 1904) to a DLP time - * structure. Put the result in 'dlpt'. - */ -void -time_palmtime2dlp(const udword palmt, - struct dlp_time *dlpt) -{ - struct tm *tm; -time_t t; - - /* Convert the Palm time to a Unix time_t */ - t = palmt - EPOCH_1904; - - /* Break the Unix time_t into components */ - tm = localtime(&t); - - /* Copy the relevant fields over to 'dlpt' */ - dlpt->year = tm->tm_year + 1900; - dlpt->month = tm->tm_mon + 1; - dlpt->day = tm->tm_mday; - dlpt->hour = tm->tm_hour; - dlpt->minute = tm->tm_min; - dlpt->second = tm->tm_sec; -} -#endif - -/* debug_dump - * Dump the contents of an array of ubytes to stderr, for debugging. - */ -void -debug_dump(FILE *outfile, const char *prefix, - const ubyte *buf, const udword len) -{ - unsigned int lineoff; - - for (lineoff = 0; lineoff < len; lineoff += 16) - { - int i; - - fprintf(outfile, "%s ", prefix); - for (i = 0; i < 16; i++) - { - if (lineoff + i < len) - { - /* Regular bytes */ - fprintf(outfile, "%02x ", buf[lineoff+i]); - } else { - /* Filler at the end of the line */ - fprintf(outfile, " "); - } - } - fprintf(outfile, " | "); - for (i = 0; i < 16; i++) - { - if (lineoff + i < len) - { - /* Regular bytes */ - if (isprint(buf[lineoff+i])) - fprintf(outfile, "%c", buf[lineoff+i]); - else - fprintf(outfile, "."); - } else - break; - } - fprintf(outfile, "\n"); - } -} - /* This is for Emacs's benefit: - * Local Variables: *** - * fill-column: 75 *** - * End: *** - */ -#endif diff --git a/configure b/configure index 6d8898eea..96d45ae29 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.61 for GPSBabel 1.3.4. +# Generated by GNU Autoconf 2.60 for GPSBabel 1.3.4. # # Report bugs to . # @@ -12,8 +12,7 @@ ## M4sh Initialization. ## ## --------------------- ## -# Be more Bourne compatible -DUALCASE=1; export DUALCASE # for MKS sh +# Be Bourne compatible if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: @@ -22,13 +21,10 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else - case `(set -o) 2>/dev/null` in - *posix*) set -o posix ;; -esac - + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi - - +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh # PATH needs CR @@ -221,7 +217,7 @@ test \$exitcode = 0) || { (exit 1); exit 1; } else as_candidate_shells= as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +for as_dir in /usr/bin/posix$PATH_SEPARATOR/bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. @@ -239,6 +235,7 @@ IFS=$as_save_IFS # Try only shells that exist, to save several forks. if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { ("$as_shell") 2> /dev/null <<\_ASEOF +# Be Bourne compatible if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: @@ -247,12 +244,10 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else - case `(set -o) 2>/dev/null` in - *posix*) set -o posix ;; -esac - + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi - +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh : _ASEOF @@ -260,6 +255,7 @@ _ASEOF CONFIG_SHELL=$as_shell as_have_required=yes if { "$as_shell" 2> /dev/null <<\_ASEOF +# Be Bourne compatible if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: @@ -268,12 +264,10 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else - case `(set -o) 2>/dev/null` in - *posix*) set -o posix ;; -esac - + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi - +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh : (as_func_return () { @@ -520,28 +514,19 @@ else as_mkdir_p=false fi -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' +# Find out whether ``test -x'' works. Don't use a zero-byte file, as +# systems may use methods other than mode bits to determine executability. +cat >conf$$.file <<_ASEOF +#! /bin/sh +exit 0 +_ASEOF +chmod +x conf$$.file +if test -x conf$$.file >/dev/null 2>&1; then + as_executable_p="test -x" else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' + as_executable_p=: fi -as_executable_p=$as_test_x +rm -f conf$$.file # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -581,36 +566,36 @@ PACKAGE_BUGREPORT='BUG-REPORT-ADDRESS' # Factoring default headers for most tests. ac_includes_default="\ #include -#ifdef HAVE_SYS_TYPES_H +#if HAVE_SYS_TYPES_H # include #endif -#ifdef HAVE_SYS_STAT_H +#if HAVE_SYS_STAT_H # include #endif -#ifdef STDC_HEADERS +#if STDC_HEADERS # include # include #else -# ifdef HAVE_STDLIB_H +# if HAVE_STDLIB_H # include # endif #endif -#ifdef HAVE_STRING_H -# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +#if HAVE_STRING_H +# if !STDC_HEADERS && HAVE_MEMORY_H # include # endif # include #endif -#ifdef HAVE_STRINGS_H +#if HAVE_STRINGS_H # include #endif -#ifdef HAVE_INTTYPES_H +#if HAVE_INTTYPES_H # include #endif -#ifdef HAVE_STDINT_H +#if HAVE_STDINT_H # include #endif -#ifdef HAVE_UNISTD_H +#if HAVE_UNISTD_H # include #endif" @@ -705,7 +690,6 @@ target_alias CC CFLAGS LDFLAGS -LIBS CPPFLAGS CPP' @@ -813,10 +797,10 @@ do -disable-* | --disable-*) ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && { echo "$as_me: error: invalid feature name: $ac_feature" >&2 { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + ac_feature=`echo $ac_feature | sed 's/-/_/g'` eval enable_$ac_feature=no ;; -docdir | --docdir | --docdi | --doc | --do) @@ -832,10 +816,10 @@ do -enable-* | --enable-*) ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && { echo "$as_me: error: invalid feature name: $ac_feature" >&2 { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + ac_feature=`echo $ac_feature | sed 's/-/_/g'` eval enable_$ac_feature=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ @@ -1029,19 +1013,19 @@ do -with-* | --with-*) ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && { echo "$as_me: error: invalid package name: $ac_package" >&2 { (exit 1); exit 1; }; } - ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + ac_package=`echo $ac_package| sed 's/-/_/g'` eval with_$ac_package=\$ac_optarg ;; -without-* | --without-*) ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && { echo "$as_me: error: invalid package name: $ac_package" >&2 { (exit 1); exit 1; }; } - ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + ac_package=`echo $ac_package | sed 's/-/_/g'` eval with_$ac_package=no ;; --x) @@ -1303,7 +1287,6 @@ Some influential environment variables: CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory - LIBS libraries to pass to the linker, e.g. -l CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor @@ -1373,7 +1356,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF GPSBabel configure 1.3.4 -generated by GNU Autoconf 2.61 +generated by GNU Autoconf 2.60 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. @@ -1387,7 +1370,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by GPSBabel $as_me 1.3.4, which was -generated by GNU Autoconf 2.61. Invocation command line was +generated by GNU Autoconf 2.60. Invocation command line was $ $0 $@ @@ -1941,7 +1924,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -1981,7 +1964,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2038,7 +2021,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2079,7 +2062,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -2137,7 +2120,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2181,7 +2164,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2322,7 +2305,7 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. -for ac_file in $ac_files '' +for ac_file in $ac_files do test -f "$ac_file" || continue case $ac_file in @@ -2350,12 +2333,6 @@ done test "$ac_cv_exeext" = no && ac_cv_exeext= else - ac_file='' -fi - -{ echo "$as_me:$LINENO: result: $ac_file" >&5 -echo "${ECHO_T}$ac_file" >&6; } -if test -z "$ac_file"; then echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 @@ -2367,6 +2344,8 @@ See \`config.log' for more details." >&2;} fi ac_exeext=$ac_cv_exeext +{ echo "$as_me:$LINENO: result: $ac_file" >&5 +echo "${ECHO_T}$ac_file" >&6; } # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. @@ -2544,10 +2523,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_compiler_gnu=yes else echo "$as_me: failed program was:" >&5 @@ -2602,10 +2598,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_prog_cc_g=yes else echo "$as_me: failed program was:" >&5 @@ -2640,10 +2653,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then : else echo "$as_me: failed program was:" >&5 @@ -2679,10 +2709,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_prog_cc_g=yes else echo "$as_me: failed program was:" >&5 @@ -2798,10 +2845,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_prog_cc_c89=$ac_arg else echo "$as_me: failed program was:" >&5 @@ -2874,7 +2938,7 @@ case $as_dir/ in # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; }; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. @@ -3003,10 +3067,17 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then : else echo "$as_me: failed program was:" >&5 @@ -3040,10 +3111,17 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then # Broken: success on invalid input. continue else @@ -3108,10 +3186,17 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then : else echo "$as_me: failed program was:" >&5 @@ -3145,10 +3230,17 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then # Broken: success on invalid input. continue else @@ -3203,7 +3295,7 @@ do for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue + { test -f "$ac_path_GREP" && $as_executable_p "$ac_path_GREP"; } || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in @@ -3285,7 +3377,7 @@ do for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue + { test -f "$ac_path_EGREP" && $as_executable_p "$ac_path_EGREP"; } || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in @@ -3381,10 +3473,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_header_stdc=yes else echo "$as_me: failed program was:" >&5 @@ -3560,10 +3669,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then eval "$as_ac_Header=yes" else echo "$as_me: failed program was:" >&5 @@ -3605,8 +3731,7 @@ cat >>conftest.$ac_ext <<_ACEOF int main () { -#if ! (defined BYTE_ORDER && defined BIG_ENDIAN && defined LITTLE_ENDIAN \ - && BYTE_ORDER && BIG_ENDIAN && LITTLE_ENDIAN) +#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN bogus endian macros #endif @@ -3627,10 +3752,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then # It does; now see whether it defined to BIG_ENDIAN or not. cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ @@ -3665,10 +3807,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_c_bigendian=yes else echo "$as_me: failed program was:" >&5 @@ -3719,10 +3878,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then ac_cv_c_bigendian=yes fi @@ -3868,11 +4044,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && - $as_test_x conftest$ac_exeext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lib_m_cos=yes else echo "$as_me: failed program was:" >&5 @@ -3881,7 +4073,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 ac_cv_lib_m_cos=no fi -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi @@ -4068,11 +4260,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && - $as_test_x conftest$ac_exeext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lib_z_gzopen=yes else echo "$as_me: failed program was:" >&5 @@ -4081,7 +4289,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 ac_cv_lib_z_gzopen=no fi -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi @@ -4166,7 +4374,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_LIBUSBCONFIG="true" echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -4236,11 +4444,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && - $as_test_x conftest$ac_exeext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lib_usb_usb_interrupt_read=yes else echo "$as_me: failed program was:" >&5 @@ -4249,7 +4473,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 ac_cv_lib_usb_usb_interrupt_read=no fi -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi @@ -4412,11 +4636,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && - $as_test_x conftest$ac_exeext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lib_expat_XML_ParserCreate=yes else echo "$as_me: failed program was:" >&5 @@ -4425,7 +4665,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 ac_cv_lib_expat_XML_ParserCreate=no fi -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi @@ -4563,11 +4803,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && - $as_test_x conftest$ac_exeext; then + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then eval "$as_ac_var=yes" else echo "$as_me: failed program was:" >&5 @@ -4576,7 +4832,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 eval "$as_ac_var=no" fi -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi ac_res=`eval echo '${'$as_ac_var'}'` @@ -4591,7 +4847,7 @@ fi done -ac_config_files="$ac_config_files Makefile gbversion.h xmldoc/makedoc tools/mkcapabilities win32/gpsbabel.rc coldsync/Makefile jeeps/Makefile shapelib/Makefile zlib/empty" +ac_config_files="$ac_config_files Makefile gbversion.h xmldoc/makedoc tools/mkcapabilities win32/gpsbabel.rc jeeps/Makefile shapelib/Makefile zlib/empty" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -4713,8 +4969,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF ## M4sh Initialization. ## ## --------------------- ## -# Be more Bourne compatible -DUALCASE=1; export DUALCASE # for MKS sh +# Be Bourne compatible if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: @@ -4723,13 +4978,10 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else - case `(set -o) 2>/dev/null` in - *posix*) set -o posix ;; -esac - + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi - - +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh # PATH needs CR @@ -4953,28 +5205,19 @@ else as_mkdir_p=false fi -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' +# Find out whether ``test -x'' works. Don't use a zero-byte file, as +# systems may use methods other than mode bits to determine executability. +cat >conf$$.file <<_ASEOF +#! /bin/sh +exit 0 +_ASEOF +chmod +x conf$$.file +if test -x conf$$.file >/dev/null 2>&1; then + as_executable_p="test -x" else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' + as_executable_p=: fi -as_executable_p=$as_test_x +rm -f conf$$.file # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -4990,7 +5233,7 @@ exec 6>&1 # values after options handling. ac_log=" This file was extended by GPSBabel $as_me 1.3.4, which was -generated by GNU Autoconf 2.61. Invocation command line was +generated by GNU Autoconf 2.60. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -5018,7 +5261,7 @@ current configuration. Usage: $0 [OPTIONS] [FILE]... -h, --help print this help, then exit - -V, --version print version number and configuration settings, then exit + -V, --version print version number, then exit -q, --quiet do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions @@ -5039,7 +5282,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ GPSBabel config.status 1.3.4 -configured by $0, generated by GNU Autoconf 2.61, +configured by $0, generated by GNU Autoconf 2.60, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" Copyright (C) 2006 Free Software Foundation, Inc. @@ -5152,7 +5395,6 @@ do "xmldoc/makedoc") CONFIG_FILES="$CONFIG_FILES xmldoc/makedoc" ;; "tools/mkcapabilities") CONFIG_FILES="$CONFIG_FILES tools/mkcapabilities" ;; "win32/gpsbabel.rc") CONFIG_FILES="$CONFIG_FILES win32/gpsbabel.rc" ;; - "coldsync/Makefile") CONFIG_FILES="$CONFIG_FILES coldsync/Makefile" ;; "jeeps/Makefile") CONFIG_FILES="$CONFIG_FILES jeeps/Makefile" ;; "shapelib/Makefile") CONFIG_FILES="$CONFIG_FILES shapelib/Makefile" ;; "zlib/empty") CONFIG_FILES="$CONFIG_FILES zlib/empty" ;; diff --git a/configure.in b/configure.in index 5c20f75d9..e7bec7bd1 100644 --- a/configure.in +++ b/configure.in @@ -288,5 +288,5 @@ AC_SUBST(DOCDIR) # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul]) AC_CHECK_FUNCS([nanosleep sleep]) -AC_CONFIG_FILES([Makefile gbversion.h xmldoc/makedoc tools/mkcapabilities win32/gpsbabel.rc coldsync/Makefile jeeps/Makefile shapelib/Makefile zlib/empty]) +AC_CONFIG_FILES([Makefile gbversion.h xmldoc/makedoc tools/mkcapabilities win32/gpsbabel.rc jeeps/Makefile shapelib/Makefile zlib/empty]) AC_OUTPUT diff --git a/copilot.c b/copilot.c index 98725740e..9405b9723 100644 --- a/copilot.c +++ b/copilot.c @@ -21,8 +21,7 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #include "grtcirc.h" #define MYNAME "CoPilot Waypoint" @@ -37,7 +36,7 @@ struct record0 { pdb_double latitude; /* PDB double format, */ pdb_double longitude; /* similarly, neg = east */ pdb_double magvar; /* magnetic variation in degrees, neg = east */ - udword elevation; /* feet */ + gbuint32 elevation; /* feet */ }; struct record1 { @@ -62,39 +61,38 @@ struct record4 { pdb_float elevation; /* feet */ }; -static FILE *file_in; -static FILE *file_out; +static pdbfile *file_in, *file_out; static const char *out_fname; -static struct pdb *opdb; -static struct pdb_record *opdb_rec; +static int ct; static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); } static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); out_fname = fname; + ct = 0; } static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); } static waypoint* -read_version0(ubyte* data) +read_version0(void *data) { char *vdata; waypoint *wpt_tmp; @@ -122,7 +120,7 @@ read_version0(ubyte* data) } static waypoint* -read_version1(ubyte* data) +read_version1(void *data) { char *vdata; waypoint *wpt_tmp; @@ -151,7 +149,7 @@ read_version1(ubyte* data) } static waypoint* -read_version3(ubyte* data) +read_version3(void *data) { char *vdata; waypoint *wpt_tmp; @@ -180,7 +178,7 @@ read_version3(ubyte* data) } static waypoint* -read_version4(ubyte* data) +read_version4(void *data) { char *vdata; waypoint *wpt_tmp; @@ -211,27 +209,22 @@ read_version4(ubyte* data) static void data_read(void) { - struct pdb *pdb; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } - - if ((pdb->creator != GXPU_CREATOR && pdb->creator != AP_P_CREATOR) || - (pdb->type != wayp_TYPE && pdb->type != swpu_TYPE && - pdb->type != wayu_TYPE)) { + if ((file_in->creator != GXPU_CREATOR && file_in->creator != AP_P_CREATOR) || + (file_in->type != wayp_TYPE && file_in->type != swpu_TYPE && + file_in->type != wayu_TYPE)) { fatal(MYNAME ": Not a CoPilot file.\n"); } - if (pdb->version > 4) { - fatal(MYNAME ": %d is not a known version.\n", pdb->version); + if (file_in->version > 4) { + fatal(MYNAME ": %d is not a known version.\n", file_in->version); } - for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) { + for(pdb_rec = file_in->rec_list; pdb_rec; pdb_rec = pdb_rec->next) { waypoint *wpt_tmp; - switch (pdb->version) + switch (file_in->version) { case 0: wpt_tmp = read_version0(pdb_rec->data); @@ -247,19 +240,16 @@ data_read(void) wpt_tmp = read_version4(pdb_rec->data); break; default: - fatal(MYNAME ": Unknown version %d.\n", pdb->version); + fatal(MYNAME ": Unknown version %d.\n", file_in->version); } waypt_add(wpt_tmp); - } - free_pdb(pdb); } static void copilot_writewpt(const waypoint *wpt) { struct record4 *rec; - static int ct = 0; char *vdata; rec = xcalloc(sizeof(*rec)+1141,1); @@ -297,36 +287,23 @@ copilot_writewpt(const waypoint *wpt) } vdata += strlen( vdata ) + 1; - opdb_rec = new_Record (0, 2, ct++, (uword) (vdata-(char *)rec), (const ubyte *)rec); - - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } + pdb_write_rec(file_out, 0, 2, ct++, rec, (char *)vdata - (char *)rec); - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } xfree(rec); } static void data_write(void) { - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - - strncpy(opdb->name, out_fname, PDB_DBNAMELEN); - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; - opdb->type = wayp_TYPE; - opdb->creator = GXPU_CREATOR; - opdb->version = 4; + strncpy(file_out->name, out_fname, PDB_DBNAMELEN); + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->type = wayp_TYPE; + file_out->creator = GXPU_CREATOR; + file_out->version = 4; waypt_disp_all(copilot_writewpt); - - pdb_Write(opdb, fileno(file_out)); } diff --git a/coto.c b/coto.c index 4b883707f..eff0692e7 100644 --- a/coto.c +++ b/coto.c @@ -26,8 +26,7 @@ #include "defs.h" #if PDBFMTS_ENABLED #include "csv_util.h" -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #include "grtcirc.h" #define MYNAME "cotoGPS" @@ -58,14 +57,14 @@ struct record_track { pdb_double arc; /* Course, unknown dimension */ pdb_double x,y; /* Internal virtual coordinates used for drawing the track on the Palm */ - word alt; /* Altitude */ + gbuint16 alt; /* Altitude */ /* accuracy and precision information for use where applicable */ gbuint16 hdop; /* _dop * 10 */ gbuint16 vdop; gbuint16 pdop; - ubyte sat_tracked; - ubyte fix_quality; + gbuint8 sat_tracked; + gbuint8 fix_quality; gbuint16 speed; /* *10 */ gbuint32 time; /* Palm Time */ @@ -84,21 +83,20 @@ struct record_wpt { typedef char appinfo_category[16]; typedef struct appinfo { - ubyte U0; - ubyte renamedCategories; + gbuint8 U0; + gbuint8 renamedCategories; appinfo_category categories[CATEGORY_NAME_LENGTH]; - ubyte ids[16]; - ubyte maxid; + gbuint8 ids[16]; + gbuint8 maxid; } appinfo_t; #define APPINFO_SIZE sizeof(appinfo_t) -static FILE *file_in; -static FILE *file_out; +static pdbfile *file_in, *file_out; static const char *out_fname; static const char *in_fname; /* We might need that for naming tracks */ -static struct pdb *opdb; static short_handle mkshort_wr_handle; +static int ct; static char *zerocat = NULL; static char *internals = NULL; @@ -115,27 +113,28 @@ arglist_t coto_args[] = { static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); in_fname = fname; } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); } static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); out_fname = fname; + ct = 0; } static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); } /* helpers */ @@ -157,16 +156,16 @@ coto_get_icon_descr(int category, const appinfo_t *app) } static void -coto_track_read(struct pdb *pdb) +coto_track_read(void) { struct record_track *rec; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; route_head *trk_head; char *track_name; - if (strncmp(pdb->name, "cotoGPS TrackDB", PDB_DBNAMELEN) != 0) + if (strncmp(file_in->name, "cotoGPS TrackDB", PDB_DBNAMELEN) != 0) // Use database name if not default - track_name = xstrndup(pdb->name, PDB_DBNAMELEN); + track_name = xstrndup(file_in->name, PDB_DBNAMELEN); else { // Use filename for new track title const char *fnametmp = strrchr(in_fname, '/'); @@ -187,7 +186,7 @@ coto_track_read(struct pdb *pdb) trk_head->rte_name = track_name; - for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) + for (pdb_rec = file_in->rec_list; pdb_rec; pdb_rec = pdb_rec->next) { waypoint *wpt_tmp; @@ -246,14 +245,14 @@ coto_track_read(struct pdb *pdb) } static void -coto_wpt_read(struct pdb *pdb) +coto_wpt_read(void) { struct record_wpt *rec; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; appinfo_t *app; - app = (struct appinfo *) pdb->appinfo; + app = (struct appinfo *) file_in->appinfo; - for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) + for(pdb_rec = file_in->rec_list; pdb_rec; pdb_rec = pdb_rec->next) { waypoint *wpt_tmp; char *c; @@ -287,49 +286,42 @@ coto_wpt_read(struct pdb *pdb) static void data_read(void) { - struct pdb *pdb; - - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } - - if ((pdb->creator != MYCREATOR) || ((pdb->type != MYTYPETRACK) && (pdb->type != MYTYPEWPT))) { - warning("Creator %x Type %x Version %d\n", (int) pdb->creator, (int) pdb->type, (int) pdb->version); + if ((file_in->creator != MYCREATOR) || ((file_in->type != MYTYPETRACK) && (file_in->type != MYTYPEWPT))) { + warning("Creator %x Type %x Version %d\n", (int) file_in->creator, (int) file_in->type, (int) file_in->version); fatal(MYNAME ": Not a cotoGPS file.\n"); } - is_fatal((pdb->version > 0), + is_fatal((file_in->version > 0), MYNAME ": This file is from an unsupported newer version of cotoGPS. It may be supported in a newer version of GPSBabel.\n"); - switch(pdb->type) + switch(file_in->type) { case MYTYPETRACK: - coto_track_read(pdb); + coto_track_read(); break; case MYTYPEWPT: - coto_wpt_read(pdb); + coto_wpt_read(); break; } - - free_pdb(pdb); } static void -coto_prepare_wpt_write(struct pdb *opdb) +coto_prepare_wpt_write(void) { struct appinfo *ai; - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->type = MYTYPEWPT; - opdb->creator = MYCREATOR; - opdb->version = 0; + + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->type = MYTYPEWPT; + file_out->creator = MYCREATOR; + file_out->version = 0; - strncpy(opdb->name, "cotoGPS MarkerDB", PDB_DBNAMELEN); + strncpy(file_out->name, "cotoGPS MarkerDB", PDB_DBNAMELEN); - opdb->appinfo_len = APPINFO_SIZE; - opdb->appinfo = calloc(APPINFO_SIZE,1); + file_out->appinfo_len = APPINFO_SIZE; + file_out->appinfo = calloc(APPINFO_SIZE,1); - ai = (struct appinfo *) opdb->appinfo; + ai = (struct appinfo *) file_out->appinfo; be_write16(&ai->renamedCategories, 31); // Don't ask me why... if (zerocat) strncpy(ai->categories[0], zerocat, 16); @@ -342,13 +334,11 @@ static void coto_wpt_write(const waypoint *wpt) { struct record_wpt *rec; - struct appinfo *ai = (struct appinfo *) opdb->appinfo; - static int ct; - struct pdb_record *opdb_rec; + struct appinfo *ai = (struct appinfo *) file_out->appinfo; char *notes = NULL; char *shortname = NULL; int size; - ubyte cat = 0; + gbuint8 cat = 0; int i; mkshort_wr_handle = mkshort_new_handle(); @@ -407,14 +397,8 @@ coto_wpt_write(const waypoint *wpt) } } - opdb_rec = new_Record (0, cat, ct++, size, (const ubyte *)rec); + pdb_write_rec(file_out, 0, cat, ct++, (const gbuint8 *)rec, size); - if (opdb_rec == NULL) - fatal(MYNAME ": libpdb couldn't create record\n"); - - if (pdb_AppendRecord(opdb, opdb_rec)) - fatal(MYNAME ": libpdb couldn't append record\n"); - xfree(shortname); xfree(rec); @@ -424,22 +408,8 @@ coto_wpt_write(const waypoint *wpt) static void data_write(void) { - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - - coto_prepare_wpt_write(opdb); - + coto_prepare_wpt_write(); waypt_disp_all(coto_wpt_write); - /* - if we want waypoints from all data, we should create a new filter for that - - track_disp_all(NULL, NULL, coto_wpt_write); - route_disp_all(NULL, NULL, coto_wpt_write); - */ - - pdb_Write(opdb, fileno(file_out)); - } diff --git a/gcdb.c b/gcdb.c index aeb6723f1..0509e6546 100644 --- a/gcdb.c +++ b/gcdb.c @@ -21,8 +21,7 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #define MYNAME "GeocachingDB" #define MYTYPE 0x44415441 /* DATA */ @@ -48,11 +47,9 @@ struct dbrec { struct dbfld dbfld[1]; }; -static FILE *file_in; -static FILE *file_out; +static pdbfile *file_in, *file_out; static const char *out_fname; -static struct pdb *opdb; -static struct pdb_record *opdb_rec; +static int ct; static char *tbuf = NULL; static char *tbufp = NULL; @@ -60,26 +57,27 @@ static char *tbufp = NULL; static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); } static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); out_fname = fname; + ct = 0; } static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); if ( tbuf ) xfree(tbuf); } @@ -87,18 +85,13 @@ wr_deinit(void) static void data_read(void) { - struct pdb *pdb; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } - - if ((pdb->creator != MYCREATOR) || (pdb->type != MYTYPE)) { + if ((file_in->creator != MYCREATOR) || (file_in->type != MYTYPE)) { fatal(MYNAME ": Not a GeocachingDB file.\n"); } - for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) { + for(pdb_rec = file_in->rec_list; pdb_rec; pdb_rec=pdb_rec->next) { waypoint *wpt = waypt_new(); struct dbrec *rec = (struct dbrec *) pdb_rec->data; int nflds; @@ -182,8 +175,6 @@ data_read(void) wpt->longitude = lon_dir * (lon_deg + lon_min/60); waypt_add(wpt); } - - free_pdb(pdb); } @@ -236,7 +227,6 @@ static void gcdb_write_wpt(const waypoint *wpt) { struct dbrec *rec; - static int ct; int reclen; char tbuf[100]; @@ -294,39 +284,23 @@ gcdb_write_wpt(const waypoint *wpt) */ reclen = gcdb_add_to_rec(rec, NULL, 0, NULL); - opdb_rec = new_Record(0, 2, ct++, (uword) reclen, (const ubyte *)rec); - - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } - - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } - + pdb_write_rec(file_out, 0, 2, ct++, rec, reclen); xfree(rec); } static void data_write(void) { - - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - - strncpy(opdb->name, out_fname, PDB_DBNAMELEN); - strncpy(opdb->name, "GeocachingDB", PDB_DBNAMELEN); - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; - opdb->type = MYTYPE; /* CWpt */ - opdb->creator = MYCREATOR; /* cGPS */ - opdb->version = 1; + strncpy(file_out->name, out_fname, PDB_DBNAMELEN); + strncpy(file_out->name, "GeocachingDB", PDB_DBNAMELEN); + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->type = MYTYPE; /* CWpt */ + file_out->creator = MYCREATOR; /* cGPS */ + file_out->version = 1; waypt_disp_all(gcdb_write_wpt); - - pdb_Write(opdb, fileno(file_out)); } diff --git a/geoniche.c b/geoniche.c index 7be79803c..d9a6c0f53 100644 --- a/geoniche.c +++ b/geoniche.c @@ -22,8 +22,7 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #include "jeeps/gpsmath.h" #include "garmin_tables.h" @@ -37,11 +36,10 @@ #undef GEONICHE_DBG -static FILE *FileIn; -static FILE *FileOut; +static pdbfile *file_in, *file_out; static const char *FilenameOut; -static struct pdb *PdbOut; - +static int rec_ct; +static int ct; static char Rec0Magic[] = "68000NV4Q2"; static char *Arg_dbname = NULL; @@ -118,13 +116,13 @@ id2gid(char gid[6+1], int id) static void rd_init(const char *fname) { - FileIn = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void rd_deinit(void) { - fclose(FileIn); + pdb_close(file_in); ARG_FREE(Arg_dbname); ARG_FREE(Arg_category); } @@ -132,14 +130,14 @@ rd_deinit(void) static void wr_init(const char *fname) { - FileOut = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); FilenameOut = fname; } static void wr_deinit(void) { - fclose(FileOut); + pdb_close(file_out); ARG_FREE(Arg_dbname); ARG_FREE(Arg_category); } @@ -190,12 +188,12 @@ eof: } static void -geoniche_read_asc(const struct pdb *pdb) +geoniche_read_asc(void) { - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; /* Process record 0 */ - pdb_rec = pdb->rec_index.rec; + pdb_rec = file_in->rec_list; if (strcmp((char *) pdb_rec->data, Rec0Magic)) fatal(MYNAME ": Bad record 0, not a GeoNiche file.\n"); pdb_rec = pdb_rec->next; @@ -225,7 +223,7 @@ geoniche_read_asc(const struct pdb *pdb) if (!wpt) fatal(MYNAME ": Couldn't allocate waypoint.\n"); vdata = (char *) pdb_rec->data; - vlen = pdb_rec->data_len; + vlen = pdb_rec->size; /* Field 1: Target */ p = field(&vdata, &vlen); @@ -436,13 +434,13 @@ geoniche_icon_to_descr(const int no) } static void -geoniche_read_bin(const struct pdb *pdb) +geoniche_read_bin(void) { - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; /* Process records */ - for (pdb_rec = pdb->rec_index.rec; pdb_rec != NULL; pdb_rec = pdb_rec->next) + for (pdb_rec = file_in->rec_list; pdb_rec != NULL; pdb_rec = pdb_rec->next) { char *vdata = (char *) pdb_rec->data; struct tm created, visited; @@ -516,27 +514,20 @@ geoniche_read_bin(const struct pdb *pdb) static void data_read(void) { - struct pdb *pdb; - - if (NULL == (pdb = pdb_Read(fileno(FileIn)))) - fatal(MYNAME ": pdb_Read failed\n"); - - if (pdb->creator != MYCREATOR) + if (file_in->creator != MYCREATOR) fatal(MYNAME ": Not a GeoNiche file.\n"); - switch(pdb->type) + switch(file_in->type) { case MYTYPE_ASC: - geoniche_read_asc(pdb); + geoniche_read_asc(); break; case MYTYPE_BIN: - geoniche_read_bin(pdb); + geoniche_read_bin(); break; default: fatal(MYNAME ": Unsupported GeoNiche file.\n"); } - - free_pdb(pdb); } static char * @@ -666,11 +657,8 @@ geoniche_geostuff(const waypoint *wpt) static void geoniche_writewpt(const waypoint *wpt) { - static int ct = 0; - struct pdb_record *opdb_rec; int vlen; - static int vsize = 4096; - ubyte *vdata; + char *vdata; char *title; struct tm tm; char datestr[10+1]; @@ -680,13 +668,8 @@ geoniche_writewpt(const waypoint *wpt) time_t tx; char *gs; - if (ct == 0) - { - opdb_rec = new_Record (0, 0, ct++, sizeof(Rec0Magic), (ubyte *) Rec0Magic); - if (opdb_rec == NULL) - fatal(MYNAME ": libpdb couldn't create record\n"); - if (pdb_AppendRecord(PdbOut, opdb_rec)) - fatal(MYNAME ": libpdb couldn't append record\n"); + if (rec_ct == 0) { + pdb_write_rec(file_out, 0, 0, ct++, Rec0Magic, sizeof(Rec0Magic)); } if ( wpt->description && wpt->description[0] ) @@ -696,7 +679,7 @@ geoniche_writewpt(const waypoint *wpt) id = gid2id(wpt->shortname); if (id < 0) - id = ct; + id = rec_ct; tx = (wpt->creation_time != 0) ? wpt->creation_time : gpsbabel_time; if (tx == 0) { /* maybe zero during testo (freezed time) */ @@ -723,13 +706,7 @@ geoniche_writewpt(const waypoint *wpt) /* last chance to fill notes with something */ if (*notes == '\0') notes = xstrappend(notes, "(notes)"); - vdata = (ubyte *) xmalloc(vsize); - if (vdata == NULL) - fatal(MYNAME ": libpdb couldn't get record memory\n"); - - for (;;) - { - vlen = snprintf((char *) vdata, vsize, + vlen = xasprintf(&vdata, "Target,%d,%s,,%s,%f,%f,%f,%s,%s,,,,%d,,,,%s" , id , title @@ -750,58 +727,37 @@ geoniche_writewpt(const waypoint *wpt) , notes ); - if (vlen > -1 && vlen < vsize) - break; - - /* try again with more space. */ - if (vlen > -1) - vsize = vlen + 1; - else - vsize *= 2; - vdata = (ubyte *) xrealloc(vdata, vsize); - if (vdata == NULL) - fatal(MYNAME ": libpdb couldn't get record memory\n"); - } - - opdb_rec = new_Record (0, 0, ct++, (uword) (vlen+1), vdata); - - if (opdb_rec == NULL) - fatal(MYNAME ": libpdb couldn't create record\n"); - if (pdb_AppendRecord(PdbOut, opdb_rec)) - fatal(MYNAME ": libpdb couldn't append record\n"); + pdb_write_rec(file_out, 0, 0, ct++, vdata, vlen + 1); xfree(notes); xfree(title); xfree(vdata); + + rec_ct++; } static void data_write(void) { - if (NULL == (PdbOut = new_pdb())) - fatal (MYNAME ": new_pdb failed\n"); - if (Arg_dbname) { if (case_ignore_strcmp(Arg_dbname, "GeoNiche Targets") == 0) fatal(MYNAME ": Reserved database name!\n"); - strncpy(PdbOut->name, Arg_dbname, PDB_DBNAMELEN); + strncpy(file_out->name, Arg_dbname, PDB_DBNAMELEN); } else - strncpy(PdbOut->name, FilenameOut, PDB_DBNAMELEN); - PdbOut->name[PDB_DBNAMELEN-1] = 0; - - PdbOut->attributes = PDB_ATTR_BACKUP; - PdbOut->ctime = PdbOut->mtime = current_time() + (49*365 + 17*366) * (60*60*24); - PdbOut->type = MYTYPE_ASC; - PdbOut->creator = MYCREATOR; - PdbOut->version = 0; - PdbOut->modnum = 1; - + strncpy(file_out->name, FilenameOut, PDB_DBNAMELEN); + file_out->name[PDB_DBNAMELEN-1] = 0; + + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + (49*365 + 17*366) * (60*60*24); + file_out->type = MYTYPE_ASC; + file_out->creator = MYCREATOR; + file_out->version = 0; + file_out->revision = 1; + + rec_ct = 0; + ct = 0; waypt_disp_all(geoniche_writewpt); - - pdb_Write(PdbOut, fileno(FileOut)); - - free_pdb(PdbOut); } diff --git a/gpilots.c b/gpilots.c index 69a2f70a8..f7ada83b3 100644 --- a/gpilots.c +++ b/gpilots.c @@ -21,8 +21,7 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #include "garmin_tables.h" #define MYNAME "GPilotS" @@ -151,12 +150,9 @@ struct record }; -static FILE *file_in; -static FILE *file_out; +static pdbfile *file_in, *file_out; static const char *out_fname; -static struct pdb *opdb; -static struct pdb_record *opdb_rec; - +static int ct = 0; static char *dbname = NULL; static @@ -168,13 +164,13 @@ arglist_t my_args[] = { static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); if ( dbname ) { xfree(dbname); dbname = NULL; @@ -184,14 +180,14 @@ rd_deinit(void) static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); out_fname = fname; } static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); if ( dbname ) { xfree(dbname); dbname = NULL; @@ -202,19 +198,14 @@ static void data_read(void) { struct record *rec; - struct pdb *pdb; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; route_head *track_head = NULL; - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } - - if (pdb->creator != MYCREATOR) { + if (file_in->creator != MYCREATOR) { fatal(MYNAME ": Not a %s file.\n", MYNAME); } - switch(pdb->type) { + switch(file_in->type) { case MYWPT: /* blah */ break; @@ -222,10 +213,10 @@ data_read(void) /* blah */ break; default: - fatal(MYNAME ": Unknown file type 0x%x\n", (int) pdb->type); + fatal(MYNAME ": Unknown file type 0x%x\n", (int) file_in->type); } - for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) { + for(pdb_rec = file_in->rec_list; pdb_rec; pdb_rec=pdb_rec->next) { waypoint *wpt_tmp; Custom_Trk_Point_Type *tp_cust; Compact_Trk_Point_Type *tp_comp; @@ -378,7 +369,6 @@ data_read(void) } } - free_pdb(pdb); } @@ -391,7 +381,6 @@ static void my_write_wpt(const waypoint *wpt) { struct record *rec; - static int ct; char *vdata; int lat, lon; @@ -406,45 +395,31 @@ my_write_wpt(const waypoint *wpt) le_write32(&rec->wpt.d103.lat, lat); le_write32(&rec->wpt.d103.lon, lon); - opdb_rec = new_Record(0, 0, ct++, (uword) (vdata - (char *) rec), (const ubyte *) rec); - - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } - - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } + pdb_write_rec(file_out, 0, 0, ct++, rec, (char *)vdata - (char *)rec); xfree(rec); } static void data_write(void) { - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - if ( dbname ) { - strncpy( opdb->name, dbname, PDB_DBNAMELEN ); + strncpy( file_out->name, dbname, PDB_DBNAMELEN ); } else { - strncpy(opdb->name, out_fname, PDB_DBNAMELEN); + strncpy(file_out->name, out_fname, PDB_DBNAMELEN); } /* * Populate header. */ - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; - opdb->type = MYWPT; - opdb->creator = MYCREATOR; - opdb->version = 1; + file_out->type = MYWPT; + file_out->creator = MYCREATOR; + file_out->version = 1; waypt_disp_all(my_write_wpt); - - pdb_Write(opdb, fileno(file_out)); } diff --git a/gpspilot.c b/gpspilot.c index 704f72e8a..31ebf8dcc 100644 --- a/gpspilot.c +++ b/gpspilot.c @@ -21,8 +21,7 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #define MYNAME "GPSPilot" #define MYTYPE_POINTS 0x706f696e /* poin */ @@ -46,12 +45,10 @@ struct runways { pdb_32 en_latitude; /* similarly */ }; -static FILE *file_in; -static FILE *file_out; +static pdbfile *file_in, *file_out; static const char *out_fname; -static struct pdb *opdb; -static struct pdb_record *opdb_rec; static char *dbname = NULL; +static int ct; static arglist_t gpspilot_args[] = { @@ -62,13 +59,13 @@ arglist_t gpspilot_args[] = { static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); if ( dbname ) { xfree(dbname); dbname = NULL; @@ -78,14 +75,15 @@ rd_deinit(void) static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); out_fname = fname; + ct = 0; } static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); if ( dbname ) { xfree(dbname); dbname = NULL; @@ -96,18 +94,13 @@ static void data_read(void) { struct record *rec; - struct pdb *pdb; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } - - if ((pdb->creator != MYCREATOR)) { + if ((file_in->creator != MYCREATOR)) { fatal(MYNAME ": Not a gpspilot file.\n"); } - switch (pdb->type) + switch (file_in->type) { case MYTYPE_AIRPORT: case MYTYPE_POINTS: @@ -119,7 +112,7 @@ data_read(void) fatal(MYNAME ": Not a gpspilot file.\n"); } - for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) { + for(pdb_rec = file_in->rec_list; pdb_rec; pdb_rec = pdb_rec->next) { waypoint *wpt_tmp; char *vdata; @@ -163,7 +156,6 @@ data_read(void) waypt_add(wpt_tmp); } - free_pdb(pdb); } @@ -171,7 +163,6 @@ static void gpspilot_writewpt(const waypoint *wpt) { struct record *rec; - static int ct = 0; char *vdata; rec = xcalloc(sizeof(*rec)+206,1); @@ -208,41 +199,28 @@ gpspilot_writewpt(const waypoint *wpt) } vdata += strlen( vdata ) + 1; - opdb_rec = new_Record (0, 2, ct++, (uword) (vdata-(char *)rec), (const ubyte *)rec); - - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } + pdb_write_rec(file_out, 0, 2, ct++, (void *)rec, (char *)vdata - (char *)rec); - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } xfree(rec); } static void data_write(void) { - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - if ( dbname ) { - strncpy(opdb->name, dbname, PDB_DBNAMELEN); + strncpy(file_out->name, dbname, PDB_DBNAMELEN); } else { - strncpy(opdb->name, out_fname, PDB_DBNAMELEN); + strncpy(file_out->name, out_fname, PDB_DBNAMELEN); } - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; - opdb->type = MYTYPE_POINTS; - opdb->creator = MYCREATOR; - opdb->version = 0; + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->type = MYTYPE_POINTS; + file_out->creator = MYCREATOR; + file_out->version = 0; waypt_disp_all(gpspilot_writewpt); - - pdb_Write(opdb, fileno(file_out)); } diff --git a/mag_pdb.c b/mag_pdb.c index 441ba6924..c9ebcca29 100644 --- a/mag_pdb.c +++ b/mag_pdb.c @@ -26,8 +26,7 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #include "jeeps/gpsmath.h" #define MYNAME "mag_pdb" @@ -35,9 +34,7 @@ #define PROUTE_MAGIC 0x766d6170 /* vmap */ #define PROUTE_ROUTE 0x49444154 /* IDAT */ -static FILE *fd_in; -static struct pdb *pdb_in; -static char *fname_in; +static pdbfile *file_in; static arglist_t magpdb_args[] = { @@ -185,34 +182,28 @@ magpdb_read_data(const char *data, const size_t data_len) static void magpdb_rd_init(const char *fname) { - fname_in = xstrdup(fname); - fd_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void magpdb_rd_deinit(void) { - fclose(fd_in); - xfree(fname_in); + pdb_close(file_in); } static void magpdb_read(void) { - struct pdb_record *pdb_rec = NULL; - + pdbrec_t *pdb_rec; - pdb_in = pdb_Read(fileno(fd_in)); - is_fatal((pdb_in == NULL), MYNAME ": read failed."); - - is_fatal((pdb_in->creator != PROUTE_MAGIC), /* identify the database */ - MYNAME ": Not a Map&Guide pdb file (0x%08x).", pdb_in->creator); + is_fatal((file_in->creator != PROUTE_MAGIC), /* identify the database */ + MYNAME ": Not a Map&Guide pdb file (0x%08x).", file_in->creator); - is_fatal((pdb_in->version != 0), /* only version "0" currently seen and tested */ - MYNAME ": This file is from an unsupported version (%d) of Map&Guide and is unsupported.", pdb_in->version + 5); + is_fatal((file_in->version != 0), /* only version "0" currently seen and tested */ + MYNAME ": This file is from an unsupported version (%d) of Map&Guide and is unsupported.", file_in->version + 5); - is_fatal((pdb_in->type != PROUTE_ROUTE), - MYNAME ": Unknown pdb data type (0x%08x).", pdb_in->type); + is_fatal((file_in->type != PROUTE_ROUTE), + MYNAME ": Unknown pdb data type (0x%08x).", file_in->type); - for (pdb_rec = pdb_in->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) + for (pdb_rec = file_in->rec_list; pdb_rec; pdb_rec = pdb_rec->next) { char *data = (char *)pdb_rec->data; @@ -222,7 +213,6 @@ static void magpdb_read(void) magpdb_read_data(data + 4, len); } } - free_pdb(pdb_in); } /* ======================================================================================= */ diff --git a/magnav.c b/magnav.c index 79a5e255f..d1e91d3c9 100644 --- a/magnav.c +++ b/magnav.c @@ -21,8 +21,7 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #define MYNAME "Companion Waypoints" #define MYTYPE 0x54777074 /* Twpt */ @@ -50,39 +49,36 @@ struct record { char unknown3; /* always 'a' */ }; -static FILE *file_in; -static FILE *file_out; -static const char *out_fname; +static pdbfile *file_in; +static pdbfile *file_out; static short_handle mkshort_handle; - -static struct pdb *opdb; -static struct pdb_record *opdb_rec; +static int ct; static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); } static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); - out_fname = fname; + file_out = pdb_create(fname, MYNAME); mkshort_handle = mkshort_new_handle(); setshort_length(mkshort_handle, 20); + ct = 0; } static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); mkshort_del_handle(&mkshort_handle); } @@ -90,18 +86,13 @@ static void data_read(void) { struct record *rec; - struct pdb *pdb; - struct pdb_record *pdb_rec; - - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } + pdbrec_t *pdb_rec; - if ((pdb->creator != MYCREATOR) || (pdb->type != MYTYPE)) { + if ((file_in->creator != MYCREATOR) || (file_in->type != MYTYPE)) { fatal(MYNAME ": Not a Magellan Navigator file.\n"); } - for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) { + for(pdb_rec = file_in->rec_list; pdb_rec; pdb_rec = pdb_rec->next) { waypoint *wpt_tmp; char *vdata; struct tm tm; @@ -133,7 +124,6 @@ data_read(void) waypt_add(wpt_tmp); } - free_pdb(pdb); } @@ -141,7 +131,6 @@ static void my_writewpt(const waypoint *wpt) { struct record *rec; - static int ct; struct tm *tm; char *vdata; time_t tm_t; @@ -206,15 +195,8 @@ my_writewpt(const waypoint *wpt) vdata[1] = '\0'; vdata += 2; - opdb_rec = new_Record (0, 0, ct++, (uword) (vdata-(char *)rec), (const ubyte *)rec); - - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } + pdb_write_rec(file_out, 0, 0, ct++, rec, (char *)vdata - (char *)rec); - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } xfree(rec); } @@ -242,23 +224,16 @@ data_write(void) "\0\x01\x02\x03\x04\x05\x06\x07\x08" "\x09\x0a\x0b\x0c\x0d\x0e\x0f\0\0"; - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - - strncpy(opdb->name, "Companion Waypoints", PDB_DBNAMELEN); - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; - opdb->type = MYTYPE; /* CWpt */ - opdb->creator = MYCREATOR; /* cGPS */ - opdb->version = 1; - opdb->appinfo = (void *)appinfo; - opdb->appinfo_len = 276; + strncpy(file_out->name, "Companion Waypoints", PDB_DBNAMELEN); + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->type = MYTYPE; /* CWpt */ + file_out->creator = MYCREATOR; /* cGPS */ + file_out->version = 1; + file_out->appinfo = (void *)appinfo; + file_out->appinfo_len = 276; waypt_disp_all(my_writewpt); - - pdb_Write(opdb, fileno(file_out)); } diff --git a/mapopolis.c b/mapopolis.c index 151cc7d99..aca520872 100644 --- a/mapopolis.c +++ b/mapopolis.c @@ -21,8 +21,7 @@ #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #define MYNAME "Companion Waypoints" #define MYTYPE 0x64617461 /* Platdata */ @@ -65,31 +64,25 @@ struct record { pdb_16 lat2d; }; -static FILE *file_in; -static FILE *file_out; -static const char *out_fname; +static pdbfile *file_in, *file_out; static short_handle mkshort_handle; -struct pdb *opdb; -struct pdb_record *opdb_rec; - static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, "rb", MYNAME); } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); } static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); - out_fname = fname; + file_out = pdb_create(fname, MYNAME); mkshort_handle = mkshort_new_handle(); setshort_length(mkshort_handle, 20); } @@ -97,7 +90,7 @@ wr_init(const char *fname) static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); mkshort_del_handle(&mkshort_handle); } @@ -129,18 +122,13 @@ decode(char *buf) } } - static void - data_read(void) +static void +data_read(void) { struct record *rec; - struct pdb *pdb; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } - - if ((pdb->creator != MYCREATOR) || (pdb->type != MYTYPE)) { + if ((file_in->creator != MYCREATOR) || (file_in->type != MYTYPE)) { fatal(MYNAME ": Not a Magellan Navigator file.\n"); } @@ -148,14 +136,14 @@ decode(char *buf) convert_rec0((struct record0*) pdb_rec->data); // for(pdb_rec = pdb->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) { - for(pdb_rec=pdb_rec->next; pdb_rec; pdb_rec=pdb_rec->next) { + for(pdb_rec = pdb_rec->next; pdb_rec; pdb_rec=pdb_rec->next) { waypoint *wpt_tmp; char *vdata = 0; char *edata; struct tm tm = {0}; rec = (struct record *) pdb_rec->data; - edata = (char *) rec + pdb_rec->data_len; + edata = (char *) rec + pdb_rec->sz; for (; vdata < edata; rec = (struct record *) vdata) { wpt_tmp = waypt_new(); @@ -251,15 +239,8 @@ my_writewpt(const waypoint *wpt) vdata[1] = '\0'; vdata += 2; - opdb_rec = new_Record (0, 0, ct++, vdata-(char *)rec, (const ubyte *)rec); - - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } + pdb_write(file_out, 0, rec, (char *)vdata - (char *)rec); - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } xfree(rec); #endif } @@ -288,23 +269,17 @@ data_write(void) "\0\x01\x02\x03\x04\x05\x06\x07\x08" "\x09\x0a\x0b\x0c\x0d\x0e\x0f\0\0"; - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - - strncpy(opdb->name, "Companion Waypoints", PDB_DBNAMELEN); - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; - opdb->type = MYTYPE; /* CWpt */ - opdb->creator = MYCREATOR; /* cGPS */ - opdb->version = 1; - opdb->appinfo = (void *)appinfo; - opdb->appinfo_len = 276; + strncpy(file_out->name, "Companion Waypoints", PDB_DBNAMELEN); + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->type = MYTYPE; /* CWpt */ + file_out->creator = MYCREATOR; /* cGPS */ + file_out->version = 1; + file_out->appinfo = (void *)appinfo; + file_out->appinfo_len = 276; waypt_disp_all(my_writewpt); - - pdb_Write(opdb, fileno(file_out)); } diff --git a/msvc/GPSBabel-msvc7.vcproj b/msvc/GPSBabel-msvc7.vcproj index ba5f6cfe7..360343b0b 100644 --- a/msvc/GPSBabel-msvc7.vcproj +++ b/msvc/GPSBabel-msvc7.vcproj @@ -22,7 +22,7 @@ Name="VCCLCompilerTool" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="expatw,..\coldsync,." + AdditionalIncludeDirectories="expatw,." PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;NDEBUG;_CONSOLE;__WIN32__;XML_UNICODE" StringPooling="TRUE" RuntimeLibrary="4" @@ -82,7 +82,7 @@ + + + + + + + + - - - - - - - - - - - - - - - - - - @@ -2352,6 +2319,9 @@ + + @@ -2361,22 +2331,6 @@ - - - - - - - - - - diff --git a/msvc/GPSBabel.dsp b/msvc/GPSBabel.dsp index c1fcba872..225d705a8 100644 --- a/msvc/GPSBabel.dsp +++ b/msvc/GPSBabel.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /WX /GX /O2 /I "expat" /I "..\coldsync" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "__WIN32__" /D VERSION=\"1.2.6_beta06232005_msvc\" /YX /FD /c +# ADD CPP /nologo /W3 /WX /GX /O2 /I "expat" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "__WIN32__" /D VERSION=\"1.2.6_beta06232005_msvc\" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /WX /Gm /GX /ZI /Od /I "expat" /I "..\coldsync" /D "WIN32" /D "__WIN32__" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D VERSION=\"1.2.6_beta06232005_msvc\" /FR /YX /FD /GZ /c +# ADD CPP /nologo /W3 /WX /Gm /GX /ZI /Od /I "expat" /D "WIN32" /D "__WIN32__" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D VERSION=\"1.2.6_beta06232005_msvc\" /FR /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -253,40 +253,6 @@ SOURCE=..\jeeps\gpsutil.c !ENDIF -# End Source File -# End Group -# Begin Group "Coldsync" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\coldsync\pdb.c - -!IF "$(CFG)" == "GPSBabel - Win32 Release" - -# PROP Intermediate_Dir "Release\Coldsync" - -!ELSEIF "$(CFG)" == "GPSBabel - Win32 Debug" - -# PROP Intermediate_Dir "Debug\Coldsync" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\coldsync\util.c - -!IF "$(CFG)" == "GPSBabel - Win32 Release" - -# PROP Intermediate_Dir "Release\Coldsync" - -!ELSEIF "$(CFG)" == "GPSBabel - Win32 Debug" - -# PROP Intermediate_Dir "Debug\Coldsync" - -!ENDIF - # End Source File # End Group # Begin Group "ShapeLib" @@ -617,26 +583,6 @@ SOURCE=.\Expat\libexpat.lib # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Group "Coldsync-Headers" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\coldsync\config.h -# End Source File -# Begin Source File - -SOURCE=..\coldsync\palm.h -# End Source File -# Begin Source File - -SOURCE=..\coldsync\pdb.h -# End Source File -# Begin Source File - -SOURCE=..\coldsync\pconn\util.h -# End Source File -# End Group # Begin Group "Jeeps-Headers" # PROP Default_Filter "" diff --git a/msvc/GPSBabel.vcproj b/msvc/GPSBabel.vcproj index b489d9c97..f07d15321 100644 --- a/msvc/GPSBabel.vcproj +++ b/msvc/GPSBabel.vcproj @@ -47,7 +47,7 @@ EnableIntrinsicFunctions="false" FavorSizeOrSpeed="2" WholeProgramOptimization="true" - AdditionalIncludeDirectories="expat,..\coldsync,." + AdditionalIncludeDirectories="expat,." PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;NDEBUG;_CONSOLE;__WIN32__;" StringPooling="true" ExceptionHandling="0" @@ -142,7 +142,7 @@ + + @@ -3003,94 +3007,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -3200,6 +3116,10 @@ RelativePath="..\mapsend.h" > + + @@ -3208,26 +3128,6 @@ RelativePath="..\quovadis.h" > - - - - - - - - - - diff --git a/msvc/build.bat b/msvc/build.bat index 26c752aa6..12638a74d 100644 --- a/msvc/build.bat +++ b/msvc/build.bat @@ -1,9 +1,8 @@ setlocal -set include=%include%;expat;..\coldsync;c:\tools\c +set include=%include%;expat;c:\tools\c set SOURCEJEEPS=..\jeeps\gpsapp.c ..\jeeps\gpscom.c ..\jeeps\gpsmath.c ..\jeeps\gpsmem.c ..\jeeps\gpsprot.c ..\jeeps\gpsread.c ..\jeeps\gpsrqst.c ..\jeeps\gpssend.c ..\jeeps\gpsserial.c ..\jeeps\gpsusbread.c ..\jeeps\gpsusbsend.c ..\jeeps\gpsusbstub.c ..\jeeps\gpsusbwin.c ..\jeeps\gpsutil.c set SOURCEMAG=..\maggeo.c ..\magnav.c ..\magproto.c -set SOURCE=..\xmltag.c ..\strptime.c ..\trackfilter.c ..\gdb.c ..\bcr.c ..\discard.c ..\formspec.c ..\an1.c ..\arcdist.c ..\brauniger_iq.c ..\wbt-200.c ..\cetus.c ..\coastexp.c ..\coldsync\pdb.c ..\copilot.c ..\csv_util.c ..\delgpl.c ..\duplicate.c ..\easygps.c ..\filter_vecs.c ..\garmin.c ..\garmin_tables.c ..\gcdb.c ..\geo.c ..\geoniche.c ..\glogbook.c ..\google.c ..\gpilots.c ..\gpspilot.c ..\gpx.c ..\grtcirc.c ..\hiketech.c ..\holux.c ..\hsa_ndv.c ..\html.c ..\igc.c ..\internal_styles.c ..\kml.c ..\lowranceusr.c ..\main.c ..\mapopolis.c ..\mapsend.c ..\mapsource.c ..\mkshort.c ..\navicache.c ..\netstumbler.c ..\nmea.c ..\overlay.c ..\ozi.c ..\palmdoc.c ..\pathaway.c ..\pcx.c ..\polygon.c ..\position.c ..\psitrex.c ..\psp.c ..\queue.c ..\quovadis.c ..\reverse_route.c ..\route.c ..\saroute.c ..\shape.c ..\shapelib\dbfopen.c ..\shapelib\shpopen.c ..\smplrout.c ..\sort.c ..\stackfilter.c ..\tef_xml.c ..\text.c ..\tiger.c ..\tmpro.c ..\tomtom.c ..\tpg.c ..\util.c ..\util_crc.c ..\uuid.c ..\vcf.c ..\vecs.c ..\vitosmt.c ..\vmem.c ..\waypt.c ..\xcsv.c ..\xmlgeneric.c ..\fatal.c ..\globals.c ..\cet_util.c ..\cet.c ..\nmn5.c ..\nmn4.c ..\cst.c ..\msroute.c ..\stmwpp.c ..\ignrando.c ..\tpo.c -cl /c ..\coldsync\util.c -Focoldsyncutil.obj +set SOURCE=..\xmltag.c ..\strptime.c ..\trackfilter.c ..\gdb.c ..\bcr.c ..\discard.c ..\formspec.c ..\an1.c ..\arcdist.c ..\brauniger_iq.c ..\wbt-200.c ..\cetus.c ..\coastexp.c ..\copilot.c ..\csv_util.c ..\delgpl.c ..\duplicate.c ..\easygps.c ..\filter_vecs.c ..\garmin.c ..\garmin_tables.c ..\gcdb.c ..\geo.c ..\geoniche.c ..\glogbook.c ..\google.c ..\gpilots.c ..\gpspilot.c ..\gpx.c ..\grtcirc.c ..\hiketech.c ..\holux.c ..\hsa_ndv.c ..\html.c ..\igc.c ..\internal_styles.c ..\kml.c ..\lowranceusr.c ..\main.c ..\mapopolis.c ..\mapsend.c ..\mapsource.c ..\mkshort.c ..\navicache.c ..\netstumbler.c ..\nmea.c ..\overlay.c ..\ozi.c ..\palmdoc.c ..\pathaway.c ..\pcx.c ..\polygon.c ..\position.c ..\psitrex.c ..\psp.c ..\queue.c ..\quovadis.c ..\reverse_route.c ..\route.c ..\saroute.c ..\shape.c ..\shapelib\dbfopen.c ..\shapelib\shpopen.c ..\smplrout.c ..\sort.c ..\stackfilter.c ..\tef_xml.c ..\text.c ..\tiger.c ..\tmpro.c ..\tomtom.c ..\tpg.c ..\util.c ..\util_crc.c ..\uuid.c ..\vcf.c ..\vecs.c ..\vitosmt.c ..\vmem.c ..\waypt.c ..\xcsv.c ..\xmlgeneric.c ..\fatal.c ..\globals.c ..\cet_util.c ..\cet.c ..\nmn5.c ..\nmn4.c ..\cst.c ..\msroute.c ..\stmwpp.c ..\ignrando.c ..\tpo.c cl /c ..\gpsutil.c -Fogpsutil2.obj -cl /Fegpsbabel.exe %source% %sourcejeeps% %sourcemag% coldsyncutil.obj gpsutil2.obj -DVERSION=\"1\" -D__WIN32__ -DWIN32_LEAN_AND_MEAN -DNO_USB Expat\libexpat.lib +cl /Fegpsbabel.exe %source% %sourcejeeps% %sourcemag% gpsutil2.obj -DVERSION=\"1\" -D__WIN32__ -DWIN32_LEAN_AND_MEAN -DNO_USB Expat\libexpat.lib endlocal diff --git a/palmdoc.c b/palmdoc.c index a34a80164..004e534e7 100644 --- a/palmdoc.c +++ b/palmdoc.c @@ -26,23 +26,20 @@ #if PDBFMTS_ENABLED #include "jeeps/gpsmath.h" #include -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" -static FILE *file_out; +static pdbfile *file_out; static short_handle mkshort_handle; static short_handle mkshort_bookmark_handle; static const char *out_fname; -static struct pdb *opdb; -static struct pdb_record *opdb_rec; static char *suppresssep = NULL; static char *dbname = NULL; static char *bmid = NULL; static char *includelogs = NULL; -static int ct = 1; -static int offset = 0; +static int ct; +static int offset; static char *palm_encrypt; @@ -257,16 +254,8 @@ static void write_header( void ) { --recs; } - opdb_rec = new_Record (0, 0, 0, - (uword) (sizeof(struct doc_record0)+sizeof(short)*(ct-1)), (const ubyte *)rec0); + pdb_write_rec(file_out, 0, 0, 0, (void *)rec0, sizeof(struct doc_record0) + sizeof(short)*(ct-1)); - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create summary record\n"); - } - - if (pdb_InsertRecord(opdb, NULL, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't insert summary record\n"); - } xfree(rec0); } @@ -294,16 +283,7 @@ static void write_bookmarks( void ) { memset( rec.text, 0, 16 ); strncpy( rec.text, oldmark->text, 16 ); - opdb_rec = new_Record( 0, 0, ct++, - sizeof(struct bookmark_record), - (const ubyte *)&rec ); - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create bookmark record\n"); - } - - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append bookmark record\n"); - } + pdb_write_rec(file_out, 0, 0, ct++, (void *)&rec, sizeof(struct bookmark_record)); xfree( oldmark ); } @@ -318,16 +298,7 @@ static void commit_buffer( void ) { pd_compress( &buf ); - opdb_rec = new_Record (0, 0, ct++, (uword) buf.len, (const ubyte *)buf.data); - - if (opdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } - - if (pdb_AppendRecord(opdb, opdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } - + pdb_write_rec(file_out, 0, 0, ct++, (void *)buf.data, buf.len); } static void create_bookmark( char *bmtext ) { @@ -385,7 +356,7 @@ static void docfinish() { static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); out_fname = fname; mkshort_handle = mkshort_new_handle(); @@ -400,7 +371,7 @@ wr_init(const char *fname) static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); mkshort_del_handle(&mkshort_handle); mkshort_del_handle(&mkshort_bookmark_handle); @@ -581,30 +552,23 @@ palmdoc_disp(const waypoint *wpt) docprintf(50, "---------------------------\n"); else docprintf(10, "\n"); - - } static void data_write(void) { - - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - if ( dbname ) { - strncpy( opdb->name, dbname, PDB_DBNAMELEN ); + strncpy( file_out->name, dbname, PDB_DBNAMELEN ); } else { - strncpy(opdb->name, out_fname, PDB_DBNAMELEN); + strncpy(file_out->name, out_fname, PDB_DBNAMELEN); } - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; - opdb->type = DOC_TYPE; - opdb->creator = DOC_CREATOR; - opdb->version = 1; + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->type = DOC_TYPE; + file_out->creator = DOC_CREATOR; + file_out->version = 1; if (! suppresssep) docprintf(50, "---------------------------\n"); @@ -614,7 +578,6 @@ data_write(void) waypt_disp_all(palmdoc_disp); docfinish(); - pdb_Write(opdb, fileno(file_out)); } diff --git a/pathaway.c b/pathaway.c index bede7b1cf..b1461ea17 100644 --- a/pathaway.c +++ b/pathaway.c @@ -31,9 +31,8 @@ #include #include "defs.h" #if PDBFMTS_ENABLED -#include "coldsync/palm.h" -#include "coldsync/pdb.h" #include "csv_util.h" +#include "pdbfile.h" #include "strptime.h" #define MYNAME "pathaway" @@ -42,13 +41,13 @@ #define PPDB_MAGIC_WPT 0x506f4c69 /* PoLi */ #define PPDB_MAGIC 0x4b6e5772 /* KwNr */ -static FILE *fd_in, *fd_out; -static struct pdb *pdb_in, *pdb_out; -static char *fname_in, *fname_out; +static pdbfile *file_in, *file_out; +static char *fname_out; static short_handle mkshort_handle; static gpsdata_type ppdb_type; static unsigned char german_release = 0; static char *datefmt; +static int ct; typedef struct ppdb_appdata { @@ -369,22 +368,19 @@ int ppdb_decode_tm(char *str, struct tm *tm) } static -int ppdb_read_wpt(const struct pdb *pdb_in, const struct pdb_record *pdb_rec, route_head *head, int isRoute) +int ppdb_read_wpt(route_head *head, int isRoute) { char *data, *str; double altfeet; struct tm tm; - for (pdb_rec = pdb_in->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next) - { + while (pdb_read_rec(file_in, NULL, NULL, NULL, (void *)&data) >= 0) { waypoint *wpt_tmp = waypt_new(); int line = 0; + char *tmp = data; - data = (char *) pdb_rec->data; - str = csv_lineparse(data, ",", """", line++); - - while (str != NULL) - { + while ((str = csv_lineparse(tmp, ",", """", line++))) { + tmp = NULL; switch(line) { case 1: @@ -422,7 +418,6 @@ int ppdb_read_wpt(const struct pdb *pdb_in, const struct pdb_record *pdb_rec, ro break; } - str = csv_lineparse(NULL, ",", """", line++); } if (head && isRoute ) @@ -442,9 +437,9 @@ int ppdb_read_wpt(const struct pdb *pdb_in, const struct pdb_record *pdb_rec, ro static void ppdb_rd_init(const char *fname) { - fname_in = xstrdup(fname); str_pool_init(); - fd_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); + ct = 0; if (opt_date) datefmt = convert_human_date_format(opt_date); @@ -454,34 +449,29 @@ static void ppdb_rd_init(const char *fname) static void ppdb_rd_deinit(void) { - fclose(fd_in); + pdb_close(file_in); str_pool_deinit(); - xfree(fname_in); if (datefmt) xfree(datefmt); } static void ppdb_read(void) { - struct pdb_record *pdb_rec = NULL; ppdb_appdata_t *info = NULL; route_head *track_head, *route_head; const char *descr = NULL; - if (NULL == (pdb_in = pdb_Read(fileno(fd_in)))) - fatal(MYNAME ": pdb_Read failed.\n"); - - if (pdb_in->creator != PPDB_MAGIC) /* identify the database */ + if (file_in->creator != PPDB_MAGIC) /* identify the database */ fatal(MYNAME ": Not a PathAway pdb file.\n"); - if (pdb_in->version != 3) /* Currently we support only version 3 */ - fatal(MYNAME ": This file is from an untested version (%d) of PathAway and is unsupported.\n", pdb_in->version); + if (file_in->version != 3) /* Currently we support only version 3 */ + fatal(MYNAME ": This file is from an untested version (%d) of PathAway and is unsupported.\n", file_in->version); - if ((pdb_in->appinfo_len > 0) && (pdb_in->appinfo != NULL)) + if ((file_in->appinfo_len > 0) && (file_in->appinfo != NULL)) { - info = (ppdb_appdata_t *) pdb_in->appinfo; + info = (ppdb_appdata_t *) file_in->appinfo; descr = info->vehicleStr; } - switch(pdb_in->type) + switch(file_in->type) { case PPDB_MAGIC_TRK: ppdb_type = trkdata; /* as default */ @@ -514,24 +504,22 @@ static void ppdb_read(void) case trkdata: track_head = route_head_alloc(); track_add_head(track_head); - track_head->rte_name = xstrdup(pdb_in->name); - ppdb_read_wpt(pdb_in, pdb_rec, track_head, 0); + track_head->rte_name = xstrdup(file_in->name); + ppdb_read_wpt(track_head, 0); break; case rtedata: route_head = route_head_alloc(); route_add_head(route_head); - route_head->rte_name = xstrdup(pdb_in->name); - ppdb_read_wpt(pdb_in, pdb_rec, route_head, 1); + route_head->rte_name = xstrdup(file_in->name); + ppdb_read_wpt(route_head, 1); break; case wptdata: - ppdb_read_wpt(pdb_in, pdb_rec, NULL, 0); + ppdb_read_wpt(NULL, 0); break; case posndata: fatal(MYNAME ": Realtime positioning not supported.\n"); break; } - - free_pdb(pdb_in); } /* ============================================================================================ @@ -544,8 +532,9 @@ static void ppdb_wr_init(const char *fname) fname_out = xstrdup(fname); str_pool_init(); - fd_out = xfopen(fname, "wb", MYNAME); + file_out = pdb_create(fname, MYNAME); mkshort_handle = mkshort_new_handle(); + ct = 0; if (global_opts.synthesize_shortnames != 0) { @@ -568,7 +557,7 @@ static void ppdb_wr_init(const char *fname) static void ppdb_wr_deinit(void) { mkshort_del_handle(&mkshort_handle); - fclose(fd_out); + pdb_close(file_out); str_pool_deinit(); xfree(fname_out); if (datefmt) xfree(datefmt); @@ -585,8 +574,6 @@ static void ppdb_write_wpt(const waypoint *wpt) char *buff, *tmp; char latdir, longdir; int len; - struct pdb_record *rec; - static int ct; struct tm tm; buff = xcalloc(REC_SIZE, 1); @@ -653,13 +640,7 @@ static void ppdb_write_wpt(const waypoint *wpt) buff = ppdb_strcat(buff, tmp, "", &len); len = strlen(buff) + 1; - rec = new_Record(0, 0, (udword)ct++, (uword)len, (const ubyte *) buff); - - if (rec == NULL) - fatal(MYNAME ": libpdb couldn't create record\n"); - - if (pdb_AppendRecord(pdb_out, rec)) - fatal(MYNAME ": libpdb couldn't append record\n"); + pdb_write_rec(file_out, 0, 0, ct++, buff, len); xfree(buff); } @@ -668,64 +649,51 @@ static void ppdb_write_wpt(const waypoint *wpt) * track and route write callbacks */ -static void ppdb_track_header(const route_head *rte) -{ -} - -static void ppdb_track_trailer(const route_head *rte) -{ -} - - static void ppdb_write(void) { ppdb_appdata_t *appinfo = NULL; - if (NULL == (pdb_out = new_pdb())) - fatal(MYNAME ": new_pdb failed\n"); if (opt_dbname) - strncpy(pdb_out->name, opt_dbname, PDB_DBNAMELEN); + strncpy(file_out->name, opt_dbname, PDB_DBNAMELEN); - pdb_out->name[PDB_DBNAMELEN-1] = 0; - pdb_out->attributes = PDB_ATTR_BACKUP; - pdb_out->ctime = pdb_out->mtime = current_time() + 2082844800U; - pdb_out->creator = PPDB_MAGIC; - pdb_out->version = 3; + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->creator = PPDB_MAGIC; + file_out->version = 3; if (global_opts.objective != wptdata) /* Waypoint target do not need appinfo block */ { appinfo = xcalloc(PPDB_APPINFO_SIZE, 1); - pdb_out->appinfo = (void *)appinfo; - pdb_out->appinfo_len = PPDB_APPINFO_SIZE; + file_out->appinfo = (void *)appinfo; + file_out->appinfo_len = PPDB_APPINFO_SIZE; } switch(global_opts.objective) /* Only one target is possible */ { case wptdata: - if (opt_dbname == NULL) strncpy(pdb_out->name, "PathAway Waypoints", PDB_DBNAMELEN); - pdb_out->type = PPDB_MAGIC_WPT; + if (opt_dbname == NULL) strncpy(file_out->name, "PathAway Waypoints", PDB_DBNAMELEN); + file_out->type = PPDB_MAGIC_WPT; waypt_disp_all(ppdb_write_wpt); break; case trkdata: - if (opt_dbname == NULL) strncpy(pdb_out->name, "PathAway Track", PDB_DBNAMELEN); - pdb_out->type = PPDB_MAGIC_TRK; + if (opt_dbname == NULL) strncpy(file_out->name, "PathAway Track", PDB_DBNAMELEN); + file_out->type = PPDB_MAGIC_TRK; appinfo->dataBaseSubType = 0; - track_disp_all(ppdb_track_header, ppdb_track_trailer, ppdb_write_wpt); + track_disp_all(NULL, NULL, ppdb_write_wpt); break; case rtedata: - if (opt_dbname == NULL) strncpy(pdb_out->name, "PathAway Route", PDB_DBNAMELEN); - pdb_out->type = PPDB_MAGIC_TRK; + if (opt_dbname == NULL) strncpy(file_out->name, "PathAway Route", PDB_DBNAMELEN); + file_out->type = PPDB_MAGIC_TRK; appinfo->dataBaseSubType = 1; - route_disp_all(ppdb_track_header, ppdb_track_trailer, ppdb_write_wpt); + route_disp_all(NULL, NULL, ppdb_write_wpt); break; case posndata: fatal(MYNAME ": Realtime positioning not supported.\n"); break; } - pdb_Write(pdb_out, fileno(fd_out)); - if (appinfo != NULL) xfree(appinfo); } diff --git a/pdbfile.c b/pdbfile.c new file mode 100644 index 000000000..d9a95a974 --- /dev/null +++ b/pdbfile.c @@ -0,0 +1,411 @@ +/* + + Minimum support for Palm/OS database files + Copyright (C) 2007 Olaf Klein, o.b.klein@gpsbabel.org + + Written after study the Coldsync project + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + +#include "defs.h" + +#if PDBFMTS_ENABLED + +#include "gbfile.h" +#include "pdbfile.h" +#include +#include + + +#define MYNAME "pdbfile" + +/* try to read to EOF (avoid determining file-size) */ + +static void * +pdb_read_tail(gbfile *fin, gbint32 *size) +{ + int count; + char buff[256]; + char *res = NULL; + int bytes = 0; + + while ((count = gbfread(buff, 1, sizeof(buff), fin))) { + + if (!res) { + res = xmalloc(count); + memcpy(res, buff, count); + } + else { + res = xrealloc(res, bytes + count); + memcpy(&res[bytes], buff, count); + } + bytes += count; + } + if (res) res = xrealloc(res, bytes + 1); + else res = xmalloc(1); + res[bytes] = '\0'; + + if (size) *size = bytes; + return (void *)res; +} + +static void +pdb_load_data(pdbfile *fin) +{ + gbuint16 i, ct; + pdbrec_t *last_rec; + gbuint32 offs; + pdbrec_t *rec; + + /* load the header */ + fin->name = xcalloc(1, 32 + 1); + gbfread(fin->name, 1, 32, fin->file); + + fin->attr = gbfgetuint16(fin->file); + fin->version = gbfgetuint16(fin->file); + fin->ctime = gbfgetuint32(fin->file); + fin->mtime = gbfgetuint32(fin->file); + fin->btime = gbfgetuint32(fin->file); + fin->revision = gbfgetuint32(fin->file); + fin->appinfo_offs = gbfgetuint32(fin->file); + fin->index_offs = gbfgetuint32(fin->file); + fin->type = gbfgetuint32(fin->file); + fin->creator = gbfgetuint32(fin->file); + fin->uid = gbfgetuint32(fin->file); + +#if 0 + fprintf(stderr, "%s: dbname \"%s\"\n", MYNAME, fin->name); + fprintf(stderr, "%s: attr %-8x\n", MYNAME, fin->attr); + fprintf(stderr, "%s: creator %-8x\n", MYNAME, fin->creator); + fprintf(stderr, "%s: type %-8x\n", MYNAME, fin->type); + fprintf(stderr, "%s: ver %-8u\n", MYNAME, fin->version); + fprintf(stderr, "%s: app-ofs %-8u\n", MYNAME, fin->appinfo_offs); + fprintf(stderr, "%s: index-ofs %-8u\n", MYNAME, fin->index_offs); +#endif + /* ID = */ (void) gbfgetuint32(fin->file); + ct = fin->rec_ct = gbfgetuint16(fin->file); + + offs = 78; + + last_rec = NULL; + for (i = 0; i < ct; i++) { + pdbrec_t *rec; + + rec = xcalloc(1, sizeof(*rec)); + if (fin->attr & PDB_FLAG_RESOURCE) { + (void) gbfgetuint32(fin->file); /* type */ + rec->id = gbfgetint16(fin->file); + rec->offs = gbfgetuint32(fin->file); + } + else { + gbuint32 x; + + rec->offs = gbfgetint32(fin->file); + x = gbfgetuint32(fin->file); + rec->id = x & 0x0ffff; + rec->category = (x >> 24) & 0x0f; + rec->flags = (x >> 24) & 0xf0; + } + + if (last_rec == NULL) + fin->rec_list = rec; + else + last_rec->next = rec; + last_rec = rec; + } + + offs += (ct * 8); + last_rec = fin->rec_list; + + if (fin->appinfo_offs != 0) { + gbuint32 top; + + /* seek to application info offset */ + while (offs < fin->appinfo_offs) { + (void)gbfgetc(fin->file); + offs++; + } + + /* determine the length of application info */ + if (fin->index_offs != 0) top = fin->index_offs; + else top = 0x7FFFFFFU; + if (last_rec && (last_rec->offs < top)) top = last_rec->offs; + + if (top != 0x7FFFFFFU) { + fin->appinfo = xmalloc(top - offs); + fin->appinfo_len = gbfread(fin->appinfo, 1, top - offs, fin->file); + offs += fin->appinfo_len; + } + else { + gbint32 size; + fin->appinfo = pdb_read_tail(fin->file, &size); + fin->appinfo_len = size; + offs += size; + } + } + + for (rec = fin->rec_list; rec; rec = rec->next) { + /* seek to current record */ + while (offs < rec->offs) { + (void) gbfgetc(fin->file); + offs++; + } + if (rec->next) { + rec->size = (gbint32)rec->next->offs - (gbint32)offs; + if (rec->size > 0) { + rec->data = xmalloc(rec->size); + rec->size = gbfread(rec->data, 1, rec->size, fin->file); + offs += rec->size; + } + else if (rec->size < 0) { + fatal(MYNAME ": Wrong data size in record with id %d.\n", rec->id); + } + } + else { + rec->data = pdb_read_tail(fin->file, &rec->size); + offs += rec->size; + } + } +} + +pdbfile * +pdb_open(const char *filename, const char *module) +{ + pdbfile *res; + + res = xcalloc(1, sizeof(*res)); + res->file = gbfopen_be(filename, "rb", module); + res->mode = 1; + + pdb_load_data(res); + pdb_rewind(res); + + return res; +} + +int +pdb_read_rec_by_id(pdbfile *fin, const int rec_id, gbuint8 *flags, gbuint8 *category, void **data) +{ + pdbrec_t *rec; + + for (rec = fin->rec_list; rec; rec = rec->next) { + if (rec->id == rec_id) { + if (data) *data = rec->data; + if (flags) *flags = rec->flags; + if (category) *category = rec->category; + return rec->size; + } + } + return -1; +} + +pdbfile * +pdb_create(const char *filename, const char *module) +{ + pdbfile *res; + + res = xcalloc(1, sizeof(*res)); + res->name = xmalloc(PDB_DBNAMELEN + 1); + strncpy(res->name, "Palm/OS Database", PDB_DBNAMELEN); + res->file = gbfopen_be(filename, "wb", module);; + res->mode = 2; + + return res; +} + +void +pdb_write_rec(pdbfile *fout, const gbuint8 flags, const gbuint8 category, const int rec_id, const void *data, const gbuint32 size) +{ + pdbrec_t *rec, *cur; + + rec = xcalloc(1, sizeof(*rec)); + rec->category = category; + rec->flags = category; + rec->id = rec_id; + rec->size = size; + if (size > 0) { + rec->data = xmalloc(size); + memcpy(rec->data, data, size); + } + + /* insert rec into rec_list sorted by id */ + cur = fout->rec_list; + if (cur == NULL) fout->rec_list = rec; + else { + pdbrec_t *prev = NULL; + + while (cur) { + if (rec_id < cur->id) { + rec->next = cur; + if (prev == NULL) fout->rec_list = rec; + else prev->next = rec; + break; + } + else if (rec_id == cur->id) { /* Overwrite record with id ... */ + rec->next = cur->next; + if (prev == NULL) fout->rec_list = rec; + else prev->next = rec; + if (cur->data) xfree(cur->data); + xfree(cur); + cur = rec; + break; + } + prev = cur; + cur = cur->next; + } + if (! cur) { + if (prev == NULL) fout->rec_list = rec; + else prev->next = rec; + } + } + fout->rec_ct++; +} + +/* all data was buffered, write now to file */ + +static void +pdb_flush(pdbfile *file) +{ + pdbrec_t *rec; + gbfile *fout = file->file; + int len, offs; + + offs = 78; + file->index_offs = 0; + offs += (file->rec_ct * 8); + + offs += 2; + + if (file->appinfo && (file->appinfo_len > 0)) { + file->appinfo_offs = offs; + offs += file->appinfo_len; + } + else + file->appinfo_offs = 0; + + rec = file->rec_list; + while (rec) { /* prepare data records */ + rec->offs = offs; + offs += rec->size; + rec = rec->next; + } + + len = strlen(file->name); + if (len > 32) len = 32; + gbfwrite(file->name, 1, len, fout); + while (len++ < 32) gbfputc(0, fout); + + gbfputuint16(file->attr, fout); + gbfputuint16(file->version, fout); + gbfputuint32(file->ctime, fout); + gbfputuint32(file->mtime, fout); + gbfputuint32(file->btime, fout); + gbfputuint32(file->revision, fout); + gbfputuint32(file->appinfo_offs, fout); + gbfputuint32(file->index_offs, fout); + gbfputuint32(file->type, fout); + gbfputuint32(file->creator, fout); + gbfputuint32(file->uid, fout); + + gbfputuint32(0, fout); /* ? ID ? */ + gbfputuint16(file->rec_ct, fout); + + for (rec = file->rec_list; rec; rec = rec->next) { + gbuint32 attr; + + gbfputint32(rec->offs, fout); + attr = (rec->category & 0x0f) | (rec->flags & 0xf0); + gbfputint32((rec->id & 0x0ffffff) | (attr << 24), fout); + } + gbfputint16(0, fout); + + if (file->appinfo && (file->appinfo_len > 0)) { + gbfwrite(file->appinfo, 1, file->appinfo_len, fout); + } + + rec = file->rec_list; + while (rec) { + gbfwrite(rec->data, 1, rec->size, fout); + rec = rec->next; + } +} + +void +pdb_close(pdbfile *file) +{ + pdbrec_t *rec; + + if (! file) return; + + if (file->mode & 2) { +#if 0 + /* this can be done later */ + if (gpsbabel_time == 0) { /* !!! We are in testo !!! */ + file->ctime = 0; /* (now we also can do a bincompare) */ + file->mtime = 0; + file->btime = 0; + } +#endif + pdb_flush(file); + } + + gbfclose(file->file); + + if ((file->mode & 1) && file->appinfo) xfree(file->appinfo); + xfree(file->name); + + rec = file->rec_list; + while (rec) { + pdbrec_t *tmp = rec; + rec = rec->next; + + if (tmp->data) xfree(tmp->data); + xfree(tmp); + } + xfree(file); +} + +int +pdb_eof(pdbfile *fin) +{ + return (fin->rec_curr) ? 0 : 1; +} + +int +pdb_read_rec(pdbfile *fin, gbuint8 *flags, gbuint8 *category, gbuint32 *rec_id, void **data) +{ + if (pdb_eof(fin)) return -1; + else { + pdbrec_t *rec = fin->rec_curr; + fin->rec_curr = rec->next; + + if (data) *data = rec->data; + if (flags) *flags = rec->flags; + if (category) *category = rec->category; + if (rec_id) *rec_id = rec->id; + + return rec->size; + } +} + +void +pdb_rewind(pdbfile *fin) +{ + fin->rec_curr = fin->rec_list; +} + +#endif diff --git a/pdbfile.h b/pdbfile.h new file mode 100644 index 000000000..4b2888976 --- /dev/null +++ b/pdbfile.h @@ -0,0 +1,84 @@ +/* + + Minimum support for Palm/OS database files + Copyright (C) 2007 Olaf Klein, o.b.klein@gpsbabel.org + + Written after study the Coldsync project + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + +#ifndef PDBFILE_H +#define PDBFILE_H + +#include "defs.h" + +#if PDBFMTS_ENABLED + +#include "gbfile.h" +#include "gbtypes.h" + +#include + +#define PDB_DBNAMELEN 32 +#define PDB_FLAG_RESOURCE 0x0001 +#define PDB_FLAG_BACKUP 0x0008 +#define EPOCH_1904 2082844800L + +typedef struct pdbrec_s { + int offs; + int size; + gbuint32 id; + gbuint8 category; + gbuint8 flags; + char *data; + struct pdbrec_s *next; +} pdbrec_t; + +typedef struct { + gbfile *file; + char mode; /* file-mode: 1 = read / 2 = write */ + char *name; /* database name */ + gbuint16 attr; /* attributes */ + gbuint16 version; /* version */ + time_t ctime; /* creation time */ + time_t mtime; /* modification time */ + time_t btime; /* backup time */ + gbuint32 revision; + gbuint32 appinfo_offs; /* offset to application info */ + gbuint32 index_offs; /* offset to sort-index info */ + gbuint32 creator; + gbuint32 type; + gbuint32 uid; + gbuint32 rec_ct; + struct pdbrec_s *rec_list; + struct pdbrec_s *rec_curr; + void *appinfo; + int appinfo_len; +} pdbfile; + + +pdbfile *pdb_open(const char *filename, const char *module); +pdbfile *pdb_create(const char *filename, const char *module); +void pdb_close(pdbfile *file); +int pdb_eof(pdbfile *fin); +void pdb_rewind(pdbfile *fin); +int pdb_read_rec(pdbfile *fin, gbuint8 *flags, gbuint8 *category, gbuint32 *rec_id, void **data); +int pdb_read_rec_by_id(pdbfile *fin, const int rec_id, gbuint8 *flags, gbuint8 *category, void **data); +void pdb_write_rec(pdbfile *fout, const gbuint8 flags, const gbuint8 category, const int rec_id, const void *data, const gbuint32 size); + +#endif +#endif diff --git a/pilot-link/README.gpsbabel b/pilot-link/README.gpsbabel deleted file mode 100644 index 0e1fc23a9..000000000 --- a/pilot-link/README.gpsbabel +++ /dev/null @@ -1,6 +0,0 @@ -This directory is a tiny subset of the pilot-link 0.12.2 code from -http://www.pilot-link.org. It is licensed under the GPL. - -We considered conditionalizing away some of the code we didn't use, but -once we realized the compiled object size was already smaller than the -coldsync code it replaces, that didn't make sense. diff --git a/pilot-link/pi-args.h b/pilot-link/pi-args.h deleted file mode 100644 index 1ce3d67bc..000000000 --- a/pilot-link/pi-args.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * $Id: pi-args.h,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * pi-args.h: Macros for prototype definitions - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef __PILOT_ARGS_H__ -#define __PILOT_ARGS_H__ - -/** @file pi-args.h - * @brief Macros for prototype definitions - * - */ -#if ((defined(__STDC__) || defined(SABER)) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) || defined(USE_PROTOTYPE) || defined(CAN_PROTOTYPE) -# define PI_ARGS(x) x -# define PI_CONST const -#else -# define PI_ARGS(x) () -# define PI_CONST -#endif - -#endif diff --git a/pilot-link/pi-buffer.c b/pilot-link/pi-buffer.c deleted file mode 100644 index cb90369cc..000000000 --- a/pilot-link/pi-buffer.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * $Id: pi-buffer.c,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * pi-buffer.c: simple data block management for variable data storage - * - * Copyright (c) 2004-2005, Florent Pillet. - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - */ -#include -#include -#include - -#include "defs.h" -#include "pi-buffer.h" - -pi_buffer_t* -pi_buffer_new (size_t capacity) -{ - pi_buffer_t* buf; - buf = (struct pi_buffer_t *) xmalloc (sizeof (struct pi_buffer_t)); - if (buf == NULL) - return NULL; - - if (capacity <= 0) - capacity = 16; /* allocating 0 byte is illegal - use a small value instead */ - - buf->data = (unsigned char *) xmalloc (capacity); - if (buf->data == NULL) { - free (buf); - return NULL; - } - - buf->allocated = capacity; - buf->used = 0; - return buf; -} - -pi_buffer_t* -pi_buffer_expect (pi_buffer_t *buf, size_t expect) -{ - if ((buf->allocated - buf->used) >= expect) - return buf; - - if (buf->data) - buf->data = (unsigned char *) realloc (buf->data, buf->used + expect); - else - buf->data = (unsigned char *) xmalloc (expect); - - if (buf->data == NULL) { - buf->allocated = 0; - buf->used = 0; - return NULL; - } - - buf->allocated = buf->used + expect; - return buf; -} - -pi_buffer_t* -pi_buffer_append (pi_buffer_t *buf, const void *data, size_t len) -{ - if (pi_buffer_expect (buf, len) == NULL) - return NULL; - - memcpy (buf->data + buf->used, data, len); - buf->used += len; - - return buf; -} - -pi_buffer_t * -pi_buffer_append_buffer (pi_buffer_t *dest, const pi_buffer_t *src) -{ - return pi_buffer_append (dest, src->data, src->used); -} - -void -pi_buffer_clear (pi_buffer_t *buf) -{ - buf->used = 0; - if (buf->allocated > (size_t)65535) - { - buf->data = (unsigned char *) realloc (buf->data, 65535); - buf->allocated = (buf->data == NULL) ? 0 : 65535; - } -} - -void -pi_buffer_free (pi_buffer_t* buf) -{ - if (buf) { - if (buf->data) - xfree (buf->data); - xfree (buf); - } -} - -/* vi: set ts=8 sw=4 sts=4 noexpandtab: cin */ -/* ex: set tabstop=4 expandtab: */ -/* Local Variables: */ -/* indent-tabs-mode: t */ -/* c-basic-offset: 8 */ -/* End: */ diff --git a/pilot-link/pi-buffer.h b/pilot-link/pi-buffer.h deleted file mode 100644 index 4b6af9716..000000000 --- a/pilot-link/pi-buffer.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * $Id: pi-buffer.h,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * pi-buffer.h: simple data block management for variable data storage - * - * Copyright (c) 2004-2005, Florent Pillet. - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/** @file pi-buffer.h - * @brief Variable size buffer management interface - * @author Florent Pillet - * - * pi-buffer provides for a reliable and easy to use variable size buffer - * management, allowing for buffers that grow as needed to store - * variable-length data. - * - * When you create a buffer with pi_buffer_new(), you indicate an initial - * capacity that is allocated. The number of used bytes is set to 0. To - * append data to the buffer, use pi_buffer_append(). This ensures that the - * buffer grows as needed. - * - * You can access data in the buffer using the @a buffer->data member. The - * number of bytes used is always accessible using @a buffer->used. - * - * It is possible to use the pi-buffer functions on static buffers. In this - * case, you won't call pi_buffer_free() on the structure. You'll dispose of - * the memory yourself instead. Here is an example: - * - * @code - * pi_buffer_t mybuf; - * mybuf.data = (unsigned char *) malloc(256); - * mybuf.allocated = 256; - * mybuf.used = 0; - * - * // ... perform your tasks here .... - * pi_buffer_append(&mybuf, somedata, somedatasize); - * // ... - * - * free(mybuf.data); - * @endcode - */ - -#ifndef _PILOT_BUFFER_H_ -#define _PILOT_BUFFER_H_ - -#include "pi-args.h" - -#ifdef __cplusplus -extern "C" { -#endif - /** @brief Variable buffer structure */ - typedef struct pi_buffer_t { - unsigned char *data; /**< Pointer to the data */ - size_t allocated; /**< Number of bytes allocated */ - size_t used; /**< Number of allocated bytes actually used */ - } pi_buffer_t; - - /** @brief Create a new variable size buffer - * - * Dispose of this buffer with pi_buffer_free() - * - * @param capacity Initial size to allocate - * @return A newly allocated pi_buffer_t structure - */ - extern pi_buffer_t* pi_buffer_new - PI_ARGS((size_t capacity)); - - /** @brief Ensure the buffer is large enough to store @p capacity bytes of data - * - * This grows the allocated buffer as needed and updates the @a allocated - * member. Doesn't touch the @a used member. After this call succeeds, you - * can directly use the @a buffer->data pointer to store up to - * @a buffer->allocated bytes using direct memory access. - * - * @param buf The buffer to grow - * @param new_capacity The total number of bytes the buffer is expected to contain - * @return The @p buf buffer on success, NULL if a memory error happened - */ - extern pi_buffer_t* pi_buffer_expect - PI_ARGS((pi_buffer_t *buf, size_t new_capacity)); - - /** @brief Append data to the buffer - * - * Grow the buffer if needed. - * - * @param buf The buffer to grow - * @param data Pointer to the data to append - * @param len Length of the data to append - * @return The @p buf buffer on success, NULL if a memory error happened - */ - extern pi_buffer_t* pi_buffer_append - PI_ARGS((pi_buffer_t *buf, PI_CONST void *data, size_t len)); - - /** @brief Append a buffer to another buffer - * - * @param dest The buffer to append to - * @param src Buffer whose data will be appended to @p dest - * @return The @p dest buffer on success, NULL if a memory error happened - */ - extern pi_buffer_t* pi_buffer_append_buffer - PI_ARGS((pi_buffer_t *dest, PI_CONST pi_buffer_t *src)); - - /** @brief Reset the @a used member of a buffer - * - * The @p used member is set to 0. If the actual allocated bytes is large, - * the allocation may shrink to a reasonable value to prevent unneeded - * memory use. - * - * @param buf The buffer to clear - * @return The @p buf parameter - */ - extern void pi_buffer_clear - PI_ARGS((pi_buffer_t *buf)); - - /** @brief Dispose of all memory used by a buffer allocated with pi_buffer_new() - * - * After this call, the @p buf structure itself will have been freed as well. - * Do not reuse the pointer. - * - * @param buf The buffer to dispose of - */ - extern void pi_buffer_free - PI_ARGS((pi_buffer_t *buf)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/pilot-link/pi-debug.h b/pilot-link/pi-debug.h deleted file mode 100644 index c1caf68ae..000000000 --- a/pilot-link/pi-debug.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * $Id: pi-debug.h,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * pi-debug.h: Debugging utilities - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef _PILOT_DEBUG_H_ -#define _PILOT_DEBUG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "pi-args.h" - -#define PI_DBG_NONE 0x000 -#define PI_DBG_SYS 0x001 -#define PI_DBG_DEV 0x002 -#define PI_DBG_SLP 0x004 -#define PI_DBG_PADP 0x008 -#define PI_DBG_DLP 0x010 -#define PI_DBG_NET 0x020 -#define PI_DBG_CMP 0x040 -#define PI_DBG_SOCK 0x080 -#define PI_DBG_API 0x100 -#define PI_DBG_USER 0x200 -#define PI_DBG_ALL 0x400 - -#define PI_DBG_LVL_NONE 0x00 -#define PI_DBG_LVL_ERR 0x01 -#define PI_DBG_LVL_WARN 0x02 -#define PI_DBG_LVL_INFO 0x04 -#define PI_DBG_LVL_DEBUG 0x08 - -extern int pi_debug_get_types PI_ARGS((void)); -extern void pi_debug_set_types PI_ARGS((int types)); - -extern int pi_debug_get_level PI_ARGS((void)); -extern void pi_debug_set_level PI_ARGS((int level)); - -extern void pi_debug_set_file PI_ARGS((const char *path)); - -extern void pi_log PI_ARGS((int type, int level, PI_CONST char *format, ...)); - -extern void pi_dumpline - PI_ARGS((PI_CONST char *buf, size_t len, unsigned int addr)); - -extern void pi_dumpdata - PI_ARGS((PI_CONST char *buf, size_t len)); - -#ifdef PI_DEBUG -#define ASSERT(expr) \ - do { \ - if (!(expr)) { \ - pi_log (PI_DBG_ALL, PI_DBG_LVL_NONE, \ - "file %s: line %d: assertion failed: (%s)", \ - __FILE__, \ - __LINE__, \ - #expr); \ - } \ - } while (0); - -#define CHECK(type, level, expr) \ - do { \ - if ((pi_debug_get_types () & type) \ - && pi_debug_get_level () >= level) \ - expr; \ - } while (0); - -#define LOG(x) pi_log x - -#else -#define ASSERT(expr) -#define CHECK(type, level, expr) - -#define LOG(x) - -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/pilot-link/pi-dlp.h b/pilot-link/pi-dlp.h deleted file mode 100644 index 1dde10264..000000000 --- a/pilot-link/pi-dlp.h +++ /dev/null @@ -1,1856 +0,0 @@ -/* - * $Id: pi-dlp.h,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * pi-dlp.h: Desktop Link Protocol implementation (ala SLP) - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/** @file pi-dlp.h - * @brief Direct protocol interface to the device using the HotSync protocol. - * - * The DLP layer is the lowest interface layer applications can use to - * access a handheld. It provides equivalents to Palm Conduit Development - * Kit (CDK)'s SyncXXX functions, as well as a number of convenience - * functions that are not found in the CDK. - * - * Once you have a socket number and a device is connected, you can start - * using DLP calls to talk with the device. All DLP calls are @b - * synchronous: they are immediately sent to the device and the current - * thread is blocked until either a response is received, or an error - * occurs. - * - * It is a good pratice to always check errors returned by DLP calls. - * Usually, if the value is nagative, it is an error code. If the error is - * #PI_ERR_DLP_PALMOS, an error code was returned by the device itself: you - * can get this error code by calling pi_palmos_error() on the current - * socket. Besides all the Palm OS error code defined in Palm's - * documentation, there are a few values between #dlpErrNoError and - * #dlpErrUnknown which are error returned by the DLP layer itself on the - * device. - * - * The DLP protocol is the low level protocol that HotSync uses. Over the - * years, there have been several iterations of DLP. Pre-Palm OS 5 devices - * have DLP 1.2 or lower. Palm OS 5 devices have DLP 1.3 or 1.4 (Palm OS 5.2 - * and up). Cobalt (Palm OS 6) uses DLP 2.1. - * - * Devices with DLP 1.4 and later are known to support transfers of large - * records and resources (of size bigger than 64k). This is the case of the - * Tapwave Zodiac, for example. - * - * Note that some devices report an incorrect version of DLP. Some Palm OS 5 - * devices report using DLP 1.2 whereas they really support DLP 1.3. - * - * Depending on which devices you plan on being compatible with, you should adjust - * #PI_DLP_VERSION_MAJOR and #PI_DLP_VERSION_MINOR. If you want to support - * devices up to and including Palm OS 5, setting your DLP version to 1.4 is - * a good idea. If you want to be able to connect to Palm OS 6, you need to - * set your DLP version to 2.1. - */ - -#ifndef _PILOT_DLP_H_ -#define _PILOT_DLP_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include "pi-macros.h" /* For recordid_t */ -#include "pi-buffer.h" /* For pi_buffer_t */ -#include "pi-error.h" /* For PI_ERR */ - -/* version of the DLP protocol supported in this version */ -/* Hint for existing versions: - * 1.2: Palm OS 4 / Palm OS 5 (OS 5 should be 1.3 but incorrectly reports 1.2) - * 1.4: TapWave Palm OS 5 - * 2.1: Palm OS 6 - */ -#define PI_DLP_VERSION_MAJOR 1 /**< Major DLP protocol version we report to the device. */ -#define PI_DLP_VERSION_MINOR 4 /**< Minor DLP protocol version we report to the device. */ - -#ifndef SWIG - #define DLP_BUF_SIZE 0xffff /**< Kept for compatibility, applications should avoid using this value. */ -#endif /* !SWIG */ - -/** @name Internal definitions used to assemble DLP calls */ -/*@{*/ -#ifndef SWIG - #define PI_DLP_OFFSET_CMD 0 - #define PI_DLP_OFFSET_ARGC 1 - #define PI_DLP_OFFSET_ARGV 2 - - #define PI_DLP_ARG_TINY_LEN 0x000000FFL - #define PI_DLP_ARG_SHORT_LEN 0x0000FFFFL - #define PI_DLP_ARG_LONG_LEN 0xFFFFFFFFL - - #define PI_DLP_ARG_FLAG_TINY 0x00 - #define PI_DLP_ARG_FLAG_SHORT 0x80 - #define PI_DLP_ARG_FLAG_LONG 0x40 - #define PI_DLP_ARG_FLAG_MASK 0xC0 - - #define PI_DLP_ARG_FIRST_ID 0x20 -#endif /* !SWIG */ -/*@}*/ - -/** @name VFS definitions */ -/*@{*/ -#define vfsMountFlagsUseThisFileSystem 0x01 /**< Mount/Format the volume with the filesystem specified */ -#define vfsMAXFILENAME 256 /**< The maximum size of a filename in a VFS volume */ -#define vfsInvalidVolRef 0 /**< constant for an invalid volume reference, guaranteed not to represent a valid one. Use it like you would use NULL for a FILE*. */ -#define vfsInvalidFileRef 0L /**< constant for an invalid file reference, guaranteed not to represent a valid one. Use it like you would use NULL for a FILE*. */ -/*@}*/ - -typedef unsigned long FileRef; /**< Type for file references when working with VFS files and directories. */ - -/** @brief Information retrieved by dlp_VFSDirEntryEnumerate() */ -struct VFSDirInfo { - unsigned long attr; /**< File or directory attributes (see VSF File attribute definitions) */ - char name[vfsMAXFILENAME]; /**< File or directory name */ -}; - -/** @brief Information used to format a volume with dlp_VFSVolumeFormat() */ -struct VFSAnyMountParam { - unsigned short volRefNum; - unsigned short reserved; - unsigned long mountClass; -}; - -/** @brief Information used to format a volume with dlp_VFSVolumeFormat() */ -struct VFSSlotMountParam { - struct VFSAnyMountParam vfsMountParam; - unsigned short slotLibRefNum; - unsigned short slotRefNum; -}; - -/** @brief Information about a VFS volume, returned by dlp_VFSVolumeInfo() */ -struct VFSInfo { - /* 0: read-only etc. */ - unsigned long attributes; /**< Volume attributes (see #dlpVFSVolumeAttributes enum) */ - - /* 4: Filesystem type for this volume (defined below). - These you can expect to see in devices: - 'vfat' (FAT12/FAT16 with long name support) - - Other values observed: - 'twmf' (Tapwave Zodiac internal VFS) - - PalmSource defines these, but don't bet on device support: - 'afsu' (Andrew network filesystem) - 'ext2' (Linux ext2 filesystem) - 'fats' (FAT12/FAT16 with 8.3 names) - 'ffsb' (BSD block-based filesystem) - 'hfse' (Macintosh HFS+) - 'hfss' (Macintosh HFS, pre-8.x) - 'hpfs' (OS/2 High Performance Filesystem) - 'mfso' (Original Macintosh filesystem) - 'nfsu' (NFS mount) - 'novl' (Novell filesystem) - 'ntfs' (Windows NT filesystem) - */ - unsigned long fsType; /**< File system time (four-char code, see above) */ - - /* 8: Creator code of filesystem driver for this volume. */ - unsigned long fsCreator; /**< File system creator (four-char code) */ - - /* For slot based filesystems: (mountClass = VFSMountClass_SlotDriver) - 12: mount class that mounted this volume */ - unsigned long mountClass; /**< Mount class */ - - /* 16: Library on which the volume is mounted */ - int slotLibRefNum; /**< Slot library reference number */ - - /* 18: ExpMgr slot number of card containing volume */ - int slotRefNum; /**< Expansion manager slot number */ - - /* 20: Type of card media (mediaMemoryStick, mediaCompactFlash, etc.) - These you can expect to see in devices: - 'cfsh' (CompactFlash) - 'mmcd' (MultiMedia Card) - 'mstk' (Memory Stick) - 'sdig' (SD card) - - Other values observed: - 'TFFS' (palmOne Tungsten T5 internal VFS) - 'twMF' (Tapwave Zodiac internal VFS) - - PalmSource also defines these: - 'pose' (Host filesystem emulated by POSE) - 'PSim' (Host filesystem emulated by Mac Simulator) - 'ramd' (RAM disk) - 'smed' (SmartMedia) - */ - unsigned long mediaType; /**< Media type (see above) */ - - /* 24: reserved for future use (other mountclasses may need more space) */ - unsigned long reserved; /**< Reserved, set to 0 */ -}; - -/** @brief Information about the handheld user - * - * This structure is used in dlp_ReadUserInfo() and dlp_WriteUserInfo() - */ -struct PilotUser { - size_t passwordLength; - char username[128]; - char password[128]; - unsigned long userID; - unsigned long viewerID; - unsigned long lastSyncPC; - time_t successfulSyncDate; - time_t lastSyncDate; -}; - -/** @brief Device information. - * - * This structure is filled by dlp_ReadSysInfo() - */ -struct SysInfo { - unsigned long romVersion; /**< Version of the device ROM, of the form 0xMMmmffssbb where MM=Major, mm=minor, ff=fix, ss=stage, bb=build */ - unsigned long locale; /**< Locale for this device */ - unsigned char prodIDLength; /**< Length of the prodID string */ - char prodID[128]; /**< Product ID */ - unsigned short dlpMajorVersion; /**< Major version of the DLP protocol on this device */ - unsigned short dlpMinorVersion; /**< Minor version of the DLP protocol on this device */ - unsigned short compatMajorVersion; /**< Minimum major version of DLP this device is compatible with */ - unsigned short compatMinorVersion; /**< Minimum minor version of DLP this device is compatible with */ - unsigned long maxRecSize; /**< Maximum record size. Usually <=0xFFFF or ==0 for older devices (means records are limited to 64k), can be much larger for devices with DLP >= 1.4 (i.e. 0x00FFFFFE) */ -}; - -/** @brief Database information. - * - * A database information block is returned by dlp_ReadDBList(), dlp_FindDBInfo(), dlp_FindDBByName(), dlp_FindDBByOpenHandle() - * and dlp_FindDBByTypeCreator(). - */ -struct DBInfo { - int more; /**< When reading database list using dlp_ReadDBList(), this flag is set if there are more databases to come */ - char name[34]; /**< Database name, 32 characters max. */ - unsigned int flags; /**< Database flags (@see dlpDBFlags enum) */ - unsigned int miscFlags; /**< Additional database flags filled by pilot-link (@see dlpDBMiscFlags enum) */ - unsigned int version; /**< Database version number */ - unsigned long type; /**< Database type (four-char code, i.e. 'appl') */ - unsigned long creator; /**< Database creator (four-char code, i.e. 'DATA') */ - unsigned long modnum; /**< Modification count */ - unsigned int index; /**< Database index in database list */ - time_t createDate; /**< Database creation date (using the machine's local time zone) */ - time_t modifyDate; /**< Last time this database was modified (using the machine's local time zone). If the database was never modified, this field is set to 0x83DAC000 (Fri Jan 1 00:00:00 1904 GMT) */ - time_t backupDate; /**< Last time this database was backed up using HotSync. If the database was never backed up, this field is set to 0x83DAC000 (Fri Jan 1 00:00:00 1904 GMT) */ -}; - -/** @brief Size information for a database. - * - * Returned by dlp_FindDBByName(), dlp_FindDBByOpenHandle() and dlp_FindDBByTypeCreator(). - */ -struct DBSizeInfo { - unsigned long numRecords; /**< Number of records or resources */ - unsigned long totalBytes; /**< Total number of bytes occupied by the database, including header and records list */ - unsigned long dataBytes; /**< Total number of data bytes contained in the database's records or resources */ - unsigned long appBlockSize; /**< Size of the appInfo block */ - unsigned long sortBlockSize; /**< Size of the sortInfo block */ - unsigned long maxRecSize; /**< note: this field is always set to 0 on return from dlp_FindDBxxx */ -}; - -/** @brief Information about a memory card. - * - * This structure describes a device's internal storage only, not removable media. - * It is returned by dlp_ReadStorageInfo(). - */ -struct CardInfo { - int card; /**< Memory card index (most devices only have one). */ - int version; /**< Version of the card */ - int more; /**< Set if there is another card after this one */ - time_t creation; /**< Creation date (using the computer's local time zone) */ - unsigned long romSize; /**< Size of the ROM block on this card (in bytes) */ - unsigned long ramSize; /**< Size of the RAM block on this card (in bytes) */ - unsigned long ramFree; /**< Total free RAM bytes */ - char name[128]; /**< Card name */ - char manufacturer[128]; /**< Card manufacturer name */ -}; - -/** @brief Network HotSync information. - * - * Returned by dlp_ReadNetSyncInfo(). Gives the network location of a remote handheld. - */ -struct NetSyncInfo { - int lanSync; /**< Non-zero if LanSync is turned on on the device */ - char hostName[256]; /**< Device hostname if any. Null terminated string. */ - char hostAddress[40]; /**< Device host address. Null terminated string. */ - char hostSubnetMask[40]; /**< Device subnet mask. Null terminated string */ -}; - -#ifndef SWIG /* no need to clutter the bindings with this */ -enum dlpFunctions { - /* range reserved for internal use */ - dlpReservedFunc = 0x0F, - - /* DLP 1.0 FUNCTIONS START HERE (PalmOS v1.0) */ - dlpFuncReadUserInfo, /* 0x10 */ - dlpFuncWriteUserInfo, /* 0x11 */ - dlpFuncReadSysInfo, /* 0x12 */ - dlpFuncGetSysDateTime, /* 0x13 */ - dlpFuncSetSysDateTime, /* 0x14 */ - dlpFuncReadStorageInfo, /* 0x15 */ - dlpFuncReadDBList, /* 0x16 */ - dlpFuncOpenDB, /* 0x17 */ - dlpFuncCreateDB, /* 0x18 */ - dlpFuncCloseDB, /* 0x19 */ - dlpFuncDeleteDB, /* 0x1a */ - dlpFuncReadAppBlock, /* 0x1b */ - dlpFuncWriteAppBlock, /* 0x1c */ - dlpFuncReadSortBlock, /* 0x1d */ - dlpFuncWriteSortBlock, /* 0x1e */ - dlpFuncReadNextModifiedRec, /* 0x1f */ - dlpFuncReadRecord, /* 0x20 */ - dlpFuncWriteRecord, /* 0x21 */ - dlpFuncDeleteRecord, /* 0x22 */ - dlpFuncReadResource, /* 0x23 */ - dlpFuncWriteResource, /* 0x24 */ - dlpFuncDeleteResource, /* 0x25 */ - dlpFuncCleanUpDatabase, /* 0x26 */ - dlpFuncResetSyncFlags, /* 0x27 */ - dlpFuncCallApplication, /* 0x28 */ - dlpFuncResetSystem, /* 0x29 */ - dlpFuncAddSyncLogEntry, /* 0x2a */ - dlpFuncReadOpenDBInfo, /* 0x2b */ - dlpFuncMoveCategory, /* 0x2c */ - dlpProcessRPC, /* 0x2d */ - dlpFuncOpenConduit, /* 0x2e */ - dlpFuncEndOfSync, /* 0x2f */ - dlpFuncResetRecordIndex, /* 0x30 */ - dlpFuncReadRecordIDList, /* 0x31 */ - - /* DLP 1.1 FUNCTIONS ADDED HERE (PalmOS v2.0 Personal, and Professional) */ - dlpFuncReadNextRecInCategory, /* 0x32 */ - dlpFuncReadNextModifiedRecInCategory, /* 0x33 */ - dlpFuncReadAppPreference, /* 0x34 */ - dlpFuncWriteAppPreference, /* 0x35 */ - dlpFuncReadNetSyncInfo, /* 0x36 */ - dlpFuncWriteNetSyncInfo, /* 0x37 */ - dlpFuncReadFeature, /* 0x38 */ - - /* DLP 1.2 FUNCTIONS ADDED HERE (PalmOS v3.0) */ - dlpFuncFindDB, /* 0x39 */ - dlpFuncSetDBInfo, /* 0x3a */ - - /* DLP 1.3 FUNCTIONS ADDED HERE (PalmOS v4.0) */ - dlpLoopBackTest, /* 0x3b */ - dlpFuncExpSlotEnumerate, /* 0x3c */ - dlpFuncExpCardPresent, /* 0x3d */ - dlpFuncExpCardInfo, /* 0x3e */ - dlpFuncVFSCustomControl, /* 0x3f */ - dlpFuncVFSGetDefaultDir, /* 0x40 */ - dlpFuncVFSImportDatabaseFromFile, /* 0x41 */ - dlpFuncVFSExportDatabaseToFile, /* 0x42 */ - dlpFuncVFSFileCreate, /* 0x43 */ - dlpFuncVFSFileOpen, /* 0x44 */ - dlpFuncVFSFileClose, /* 0x45 */ - dlpFuncVFSFileWrite, /* 0x46 */ - dlpFuncVFSFileRead, /* 0x47 */ - dlpFuncVFSFileDelete, /* 0x48 */ - dlpFuncVFSFileRename, /* 0x49 */ - dlpFuncVFSFileEOF, /* 0x4a */ - dlpFuncVFSFileTell, /* 0x4b */ - dlpFuncVFSFileGetAttributes, /* 0x4c */ - dlpFuncVFSFileSetAttributes, /* 0x4d */ - dlpFuncVFSFileGetDate, /* 0x4e */ - dlpFuncVFSFileSetDate, /* 0x4f */ - dlpFuncVFSDirCreate, /* 0x50 */ - dlpFuncVFSDirEntryEnumerate, /* 0x51 */ - dlpFuncVFSGetFile, /* 0x52 */ - dlpFuncVFSPutFile, /* 0x53 */ - dlpFuncVFSVolumeFormat, /* 0x54 */ - dlpFuncVFSVolumeEnumerate, /* 0x55 */ - dlpFuncVFSVolumeInfo, /* 0x56 */ - dlpFuncVFSVolumeGetLabel, /* 0x57 */ - dlpFuncVFSVolumeSetLabel, /* 0x58 */ - dlpFuncVFSVolumeSize, /* 0x59 */ - dlpFuncVFSFileSeek, /* 0x5a */ - dlpFuncVFSFileResize, /* 0x5b */ - dlpFuncVFSFileSize, /* 0x5c */ - - /* DLP 1.4 functions added here (Palm OS 5.2+, ie Tapwave Zodiac) */ - dlpFuncExpSlotMediaType, /* 0x5d */ - dlpFuncWriteRecordEx, /* 0x5e - function to write >64k records in Tapwave */ - dlpFuncWriteResourceEx, /* 0x5f - function to write >64k resources in Tapwave */ - dlpFuncReadRecordEx, /* 0x60 - function to read >64k records by index in Tapwave */ - dlpFuncUnknown1, /* 0x61 (may be bogus definition in tapwave headers, is listed as dlpFuncReadRecordStream)*/ - dlpFuncUnknown3, /* 0x62 */ - dlpFuncUnknown4, /* 0x63 */ - dlpFuncReadResourceEx, /* 0x64 - function to read resources >64k by index in Tapwave */ - dlpLastFunc -}; - -#endif /* !SWIG */ - -/** @name Database and record attributes */ -/*@{*/ - /** @brief Database flags in DBInfo structure and also for dlp_CreateDB() */ - enum dlpDBFlags { - dlpDBFlagResource = 0x0001, /**< Resource database */ - dlpDBFlagReadOnly = 0x0002, /**< Database is read only */ - dlpDBFlagAppInfoDirty = 0x0004, /**< AppInfo data has been modified */ - dlpDBFlagBackup = 0x0008, /**< Database should be backed up during HotSync */ - dlpDBFlagHidden = 0x0100, /**< Database is hidden */ - dlpDBFlagLaunchable = 0x0200, /**< Database is launchable data (show in Launcher, launch app by Creator) */ - dlpDBFlagRecyclable = 0x0400, /**< Database will be deleted shortly */ - dlpDBFlagBundle = 0x0800, /**< Database is bundled with others having same creator (i.e. for Beam) */ - dlpDBFlagOpen = 0x8000, /**< Database is currently open */ - - /* v2.0 specific */ - dlpDBFlagNewer = 0x0010, /**< Newer version may be installed over open DB (Palm OS 2.0 and later) */ - dlpDBFlagReset = 0x0020, /**< Reset after installation (Palm OS 2.0 and later) */ - - /* v3.0 specific */ - dlpDBFlagCopyPrevention = 0x0040, /**< Database should not be beamed or sent (Palm OS 3.0 and later) */ - dlpDBFlagStream = 0x0080, /**< Database is a file stream (Palm OS 3.0 and later) */ - - /* OS 6+ */ - dlpDBFlagSchema = 0x1000, /**< Schema database (Palm OS 6.0 and later) */ - dlpDBFlagSecure = 0x2000, /**< Secure database (Palm OS 6.0 and later) */ - dlpDBFlagExtended = dlpDBFlagSecure, /**< Set if Schema not set and DB is Extended (Palm OS 6.0 and later) */ - dlpDBFlagFixedUp = 0x4000 /**< Temp flag used to clear DB on write (Palm OS 6.0 and later) */ - }; - - /** @brief Misc. flags in DBInfo structure */ - enum dlpDBMiscFlags { - dlpDBMiscFlagExcludeFromSync = 0x80, /**< DLP 1.1 and later: exclude this database from sync */ - dlpDBMiscFlagRamBased = 0x40 /**< DLP 1.2 and later: this database is in RAM */ - }; - - /** @brief Database record attributes */ - enum dlpRecAttributes { - dlpRecAttrDeleted = 0x80, /**< Tagged for deletion during next sync */ - dlpRecAttrDirty = 0x40, /**< Record modified */ - dlpRecAttrBusy = 0x20, /**< Record locked (in use) */ - dlpRecAttrSecret = 0x10, /**< Record is secret */ - dlpRecAttrArchived = 0x08 /**< Tagged for archival during next sync */ - }; - - /** @brief Mode flags used in dlp_OpenDB() */ - enum dlpOpenFlags { - dlpOpenRead = 0x80, /**< Open database for reading */ - dlpOpenWrite = 0x40, /**< Open database for writing */ - dlpOpenExclusive = 0x20, /**< Open database with exclusive access */ - dlpOpenSecret = 0x10, /**< Show secret records */ - dlpOpenReadWrite = 0xC0 /**< Open database for reading and writing (equivalent to (#dlpOpenRead | #dlpOpenWrite)) */ - }; - - /** @brief Flags passed to dlp_ReadDBList() */ - enum dlpDBList { - dlpDBListRAM = 0x80, /**< List RAM databases */ - dlpDBListROM = 0x40, /**< List ROM databases */ - dlpDBListMultiple = 0x20 /**< DLP 1.2 and above: list as many databases as possible at once */ - }; - - enum dlpFindDBOptFlags { - dlpFindDBOptFlagGetAttributes = 0x80, - dlpFindDBOptFlagGetSize = 0x40, - dlpFindDBOptFlagMaxRecSize = 0x20 - }; - - enum dlpFindDBSrchFlags { - dlpFindDBSrchFlagNewSearch = 0x80, - dlpFindDBSrchFlagOnlyLatest = 0x40 - }; - -/*@}*/ - -/** @brief End status values for dlp_EndOfSync() */ -enum dlpEndStatus { - dlpEndCodeNormal = 0, /**< Normal termination */ - dlpEndCodeOutOfMemory, /**< End due to low memory on device */ - dlpEndCodeUserCan, /**< Cancelled by user */ - dlpEndCodeOther /**< dlpEndCodeOther and higher == "Anything else" */ -}; - -/** @name Expansion manager and VFS manager constants */ -/*@{*/ - /** @brief Expansion card capabilities, as returned by dlp_ExpCardInfo() */ - enum dlpExpCardCapabilities { - dlpExpCapabilityHasStorage = 0x00000001, /**< Card supports reading (and maybe writing) */ - dlpExpCapabilityReadOnly = 0x00000002, /**< Card is read-only */ - dlpExpCapabilitySerial = 0x00000004 /**< Card supports dumb serial interface */ - }; - - /** @brief VFS volume attributes as found in the @a attributes member of a VFSInfo structure */ - enum dlpVFSVolumeAttributes { - vfsVolAttrSlotBased = 0x00000001, /**< Volume is inserted is an expansion slot */ - vfsVolAttrReadOnly = 0x00000002, /**< Volume is read-only */ - vfsVolAttrHidden = 0x00000004 /**< Volume is hidden */ - }; - - /** @brief Constants for dlp_VFSFileSeek() */ - enum dlpVFSSeekConstants { - vfsOriginBeginning = 0, /**< From the beginning (first data byte of file) */ - vfsOriginCurrent = 1, /**< from the current position */ - vfsOriginEnd = 2 /**< From the end of file (one position beyond last data byte, only negative offsets are legally allowed) */ - }; - - /** @brief Flags for dlp_VFSFileOpen() */ - enum dlpVFSOpenFlags { - dlpVFSOpenExclusive = 0x01, /**< For dlp_VFSFileOpen(). Exclusive access */ - dlpVFSOpenRead = 0x02, /**< For dlp_VFSFileOpen(). Read only */ - dlpVFSOpenWrite = 0x05, /**< For dlp_VFSFileOpen(). Write only. Implies exclusive */ - dlpVFSOpenReadWrite = 0x07, /**< For dlp_VFSFileOpen(). Read | write */ - - /* Remainder are aliases and special cases not for VFSFileOpen */ - vfsModeExclusive = dlpVFSOpenExclusive, /**< Alias to #dlpVFSOpenExclusive */ - vfsModeRead = dlpVFSOpenRead, /**< Alias to #dlpVFSOpenRead */ - vfsModeWrite = dlpVFSOpenWrite, /**< Alias to #dlpVFSOpenWrite */ - vfsModeReadWrite = vfsModeRead | vfsModeWrite, /**< Alias to #dlpVFSOpenReadWrite */ - vfsModeCreate = 0x08 /**< Not for dlp_VFSFileOpen(). Create file if it doesn't exist. */, - vfsModeTruncate = 0x10 /**< Not for dlp_VFSFileOpen(). Truncate to 0 bytes on open. */, - vfsModeLeaveOpen = 0x20 /**< Not for dlp_VFSFileOpen(). Leave file open even if foreground task closes. */ - } ; - - /** @brief VFS file attribute constants */ - enum dlpVFSFileAttributeConstants { - vfsFileAttrReadOnly = 0x00000001, /**< File is read only */ - vfsFileAttrHidden = 0x00000002, /**< File is hidden */ - vfsFileAttrSystem = 0x00000004, /**< File is a system file */ - vfsFileAttrVolumeLabel = 0x00000008, /**< File is the volume label */ - vfsFileAttrDirectory = 0x00000010, /**< File is a directory */ - vfsFileAttrArchive = 0x00000020, /**< File is archived */ - vfsFileAttrLink = 0x00000040 /**< File is a link to another file */ - }; - - /** @brief Constants for dlp_VFSFileGetDate() and dlp_VFSFileSetDate() */ - enum dlpVFSDateConstants { - vfsFileDateCreated = 1, /**< The date the file was created. */ - vfsFileDateModified = 2, /**< The date the file was last modified. */ - vfsFileDateAccessed = 3 /**< The date the file was last accessed. */ - }; - - /** @brief VFS file iterator constants */ - enum dlpVFSFileIteratorConstants { - vfsIteratorStart = 0, /** < Indicates that iterator is beginning */ - vfsIteratorStop = -1 /**< Indicate that iterator has gone through all items */ - }; -/*@}*/ - - -/** @brief Error codes returned by DLP transactions - * - * After a DLP transaction, there may be a DLP or Palm OS error - * if the result code is #PI_ERR_DLP_PALMOS. In this case, use - * pi_palmos_error() to obtain the error code. It can be in the - * DLP error range (0 > error < #dlpErrLastError), or otherwise - * in the Palm OS error range (see Palm OS header files for - * definitions, in relation with each DLP call) - */ -enum dlpErrors { - dlpErrNoError = 0, /**< No error */ - dlpErrSystem, /**< System error (0x0001) */ - dlpErrIllegalReq, /**< Illegal request, not supported by this version of DLP (0x0002) */ - dlpErrMemory, /**< Not enough memory (0x0003) */ - dlpErrParam, /**< Invalid parameter (0x0004) */ - dlpErrNotFound, /**< File, database or record not found (0x0005) */ - dlpErrNoneOpen, /**< No file opened (0x0006) */ - dlpErrAlreadyOpen, /**< File already open (0x0007) */ - dlpErrTooManyOpen, /**< Too many open files (0x0008) */ - dlpErrExists, /**< File already exists (0x0009) */ - dlpErrOpen, /**< Can't open file (0x000a) */ - dlpErrDeleted, /**< File deleted (0x000b) */ - dlpErrBusy, /**< Record busy (0x000c) */ - dlpErrNotSupp, /**< Call not supported (0x000d) */ - dlpErrUnused1, /**< @e Unused (0x000e) */ - dlpErrReadOnly, /**< File is read-only (0x000f) */ - dlpErrSpace, /**< Not enough space left on device (0x0010) */ - dlpErrLimit, /**< Limit reached (0x0011) */ - dlpErrSync, /**< Sync error (0x0012) */ - dlpErrWrapper, /**< Wrapper error (0x0013) */ - dlpErrArgument, /**< Invalid argument (0x0014) */ - dlpErrSize, /**< Invalid size (0x0015) */ - - dlpErrUnknown = 127 /**< Unknown error (0x007F) */ -}; - - -#ifndef SWIG /* no need to clutter the bindings with this */ - -/** @brief Internal DLP argument structure */ -struct dlpArg { - int id_; /**< Argument ID (start at #PI_DLP_ARG_FIRST_ID) */ - size_t len; /**< Argument length */ - char *data; /**< Argument data */ -}; - -/** @brief Internal DLP command request structure */ -struct dlpRequest { - enum dlpFunctions cmd; /**< Command ID */ - int argc; /**< Number of arguments */ - struct dlpArg **argv; /**< Ptr to arguments */ -}; - -/** @brief Internal DLP command response structure */ -struct dlpResponse { - enum dlpFunctions cmd; /**< Command ID as returned by device. If not the same than requested command, this is an error */ - enum dlpErrors err; /**< DLP error (see #dlpErrors enum) */ - int argc; /**< Number of response arguments */ - struct dlpArg **argv; /**< Response arguments */ -}; - -#endif /* !SWIG */ - -/* @name Functions used internally by dlp.c */ -/*@{*/ -#ifndef SWIG /* don't export these functions to bindings */ - extern struct dlpArg * dlp_arg_new PI_ARGS((int id_, size_t len)); - extern void dlp_arg_free PI_ARGS((struct dlpArg *arg)); - extern int dlp_arg_len PI_ARGS((int argc, struct dlpArg **argv)); - - extern struct dlpRequest *dlp_request_new - PI_ARGS((enum dlpFunctions cmd, int argc, ...)); - extern struct dlpRequest * dlp_request_new_with_argid - PI_ARGS((enum dlpFunctions cmd, int argid, int argc, ...)); - extern void dlp_request_free PI_ARGS((struct dlpRequest *req)); - - extern struct dlpResponse *dlp_response_new - PI_ARGS((enum dlpFunctions cmd, int argc)); - extern ssize_t dlp_response_read PI_ARGS((struct dlpResponse **res, - int sd)); - extern ssize_t dlp_request_write PI_ARGS((struct dlpRequest *req, - int sd)); - extern void dlp_response_free PI_ARGS((struct dlpResponse *req)); - - extern int dlp_exec PI_ARGS((int sd, struct dlpRequest *req, - struct dlpResponse **res)); - - extern char *dlp_errorlist[]; - extern char *dlp_strerror(int error); - - struct RPC_params; - extern int dlp_RPC - PI_ARGS((int sd, struct RPC_params * p, - unsigned long *result)); -#endif /* !SWIG */ -/*@}*/ - -/** @name DLP library functions */ -/*@{*/ - /** @brief Set the version of the DLP protocol we report to the device. - * - * During the handshake phase, the device and the desktop exchange the - * version of the DLP protocol both support. If the device's DLP version - * is higher than the desktop's, the device usually refuses to connect. - * - * @note Call this function prior to accepting or initiating a connection. - * - * @param major Protocol major version - * @param minor Protocol minor version - */ - extern void dlp_set_protocol_version - PI_ARGS((int major, int minor)); - - /** @brief Convert a Palm OS date to a local date - * - * Local dates are using the local machine's timezone. If the Palm OS date - * is undefined, the local date is set to @c 0x83DAC000 (Fri Jan 1 00:00:00 1904 GMT) - * - * @param timeDateData Ptr to a time/date data block returned by Palm OS - * @return converted date - */ - extern time_t dlp_ptohdate PI_ARGS((PI_CONST unsigned char *timeDateData)); - - /** @brief Convert a date to Palm OS date - * - * If the local date is @c 0x83DAC000 (Fri Jan 1 00:00:00 1904 GMT) the Palm OS date - * is set to undefined. Otherwise the date is converted from local time to Palm OS - * - * @param palm_time The date to convert - * @param timeDateData Ptr to an 8 byte buffer to hold the Palm OS date - */ - extern void dlp_htopdate PI_ARGS((time_t palm_time, unsigned char *timeDateData)); -/*@}*/ - -/** @name System functions */ -/*@{*/ - /** @brief Get the time from the device and return it as a local time_t value - * - * @param sd Socket number - * @param palm_time Pointer to a time_t to fill - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_GetSysDateTime PI_ARGS((int sd, time_t *palm_time)); - - /** @brief Set the time on the Palm using a local time_t value. - * - * @param sd Socket number - * @param palm_time New time to set the device to (expressed using the computer's timezone) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_SetSysDateTime PI_ARGS((int sd, time_t palm_time)); - - /** @brief Read the system information block - * - * @param sd Socket number - * @param sysinfo Returned system information - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadSysInfo PI_ARGS((int sd, struct SysInfo *sysinfo)); - - /** @brief Read information about internal handheld memory - * - * @param sd Socket number - * @param cardno Card number (zero based) - * @param cardinfo Returned information about the memory card. - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadStorageInfo - PI_ARGS((int sd, int cardno, struct CardInfo *cardinfo)); - - /** @brief Read the device user information - * - * @param sd Socket number - * @param user Returned user info - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadUserInfo - PI_ARGS((int sd, struct PilotUser *user)); - - /** @brief Change the device user information - * - * @param sd Socket number - * @param INPUT New user info - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_WriteUserInfo - PI_ARGS((int sd, PI_CONST struct PilotUser *INPUT)); - - /** @brief Convenience function to reset lastSyncPC in the UserInfo to 0 - * - * @param sd Socket number - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ResetLastSyncPC PI_ARGS((int sd)); - - /** @brief Read Network HotSync information - * - * Supported on Palm OS 2.0 and later. - * - * @param sd Socket number - * @param OUTPUT On return, filled NetSyncInfo structure - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadNetSyncInfo - PI_ARGS((int sd, struct NetSyncInfo *OUTPUT)); - - /** @brief Set Network HotSync information - * - * Supported on Palm OS 2.0 and later - * - * @param sd Socket number - * @param INPUT NetSyncInfo structure to set - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_WriteNetSyncInfo - PI_ARGS((int sd, PI_CONST struct NetSyncInfo *INPUT)); - - /** @brief State that a conduit has started running on the desktop - * - * Puts up a status message on the device. Calling this method regularly - * is also the only reliable way to know whether the user pressed the Cancel - * button on the device. - * - * @param sd Socket number - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_OpenConduit PI_ARGS((int sd)); - - /** @brief Terminate connection with the device - * - * Required at the end of a session. The pi_socket layer - * will call this for you if you don't. After the device receives this - * command, it will terminate the connection. - * - * @param sd Socket number - * @param status End of sync status (see #dlpEndStatus enum) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_EndOfSync PI_ARGS((int sd, int status)); - - /** @brief Terminate HotSync _without_ notifying Palm. - * - * This will cause the Palm to time out, and should (if I remember right) - * lose any changes to unclosed databases. _Never_ use under ordinary - * circumstances. If the sync needs to be aborted in a reasonable - * manner, use EndOfSync with a non-zero status. - * - * @param sd Socket number - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_AbortSync PI_ARGS((int sd)); - - /** @brief Read a Feature from the device - * - * @param sd Socket number - * @param creator Feature creator - * @param num Feature number - * @param feature On return, the feature value - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadFeature - PI_ARGS((int sd, unsigned long creator, int num, - unsigned long *feature)); - - /** @brief Emulation of the SysGetROMToken function on the device - * - * Supported on Palm OS 2.0 through 4.0. Using this function - * is not recommended. - * - * @warning This function uses 68K RPC calls to perform its duty, - * and is therefore not supported on devices running Palm OS 5.0 - * and later. Actually, it may even crash the device. - * - * @param sd Socket number - * @param token ROM token to read - * @param databuf Buffer to store the token data in - * @param datasize Size of data to read - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_GetROMToken - PI_ARGS((int sd, unsigned long token, void *databuf, size_t *datasize)); - - /** @brief Add an entry into the HotSync log on the device - * - * Move to the next line with \\n, as usual. You may invoke this - * command once or more before calling dlp_EndOfSync(), but it is - * not required. - * - * @param sd Socket number - * @param string Nul-terminated string with the text to insert in the log - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_AddSyncLogEntry PI_ARGS((int sd, char *string)); - - /** @brief Call an application on the device - * - * 32-bit retcode and data over 64k only supported on Palm OS 2.0 and later. - * - * This function allows calling an application (or any PRC that responds - * to launch codes) using a custom launch code and custom data. The - * application can return data too, using DlkControl() and the - * dlkCtlSendCallAppReply selector. See Palm OS documentation for more - * information. - * - * @param sd Socket number - * @param creator Creator code of the application to call - * @param type Type code of the application to call - * @param action Launch code to send to the application - * @param datasize Length of data block to pass to the application - * @param databuf Data block to pass to the application - * @param retcode On return, result code returned by the application - * @param retbuf Buffer allocated using pi_buffer_new(). On return contains the data returned by the application - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_CallApplication - PI_ARGS((int sd, unsigned long creator, unsigned long type, - int action, size_t datasize, PI_CONST void *databuf, - unsigned long *retcode, pi_buffer_t *retbuf)); - - /** @brief Convenience function to ead an app preference data block - * - * Supported on Palm OS 2.0 and later, emulated for Palm OS 1.x. - * - * @param sd Socket number - * @param creator Application creator - * @param prefid Preference ID - * @param backup If set, read from backup prefs (see Palm OS documentation). This flag is ignored on Palm OS 1.x. - * @param maxsize Maximum size of the data to return in buffer - * @param databuf If not NULL, buffer should be of size @p maxsize. On return, contains the preference data - * @param datasize If not NULL, on return contains the size of the preference data block - * @param version If not NULL - * @return A negative value if an error occured (see pi-error.h), otherwise the size of the preference block - */ - extern PI_ERR dlp_ReadAppPreference - PI_ARGS((int sd, unsigned long creator, int prefid, int backup, - int maxsize, void *databuf, size_t *datasize, int *version)); - - /** @brief Write an app preference data block - * - * Supported on Palm OS 2.0 and later. Emulated on Palm OS 1.x. - * - * @param sd Socket number - * @param creator Application creator - * @param prefid Preference ID - * @param backup If set, write to backup prefs (see Palm OS documentation). This flag is ignored on Palm OS 1.x. - * @param version Version of the pref to write - * @param databuf Ptr to the data to write - * @param datasize Size of the data to write - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_WriteAppPreference - PI_ARGS((int sd, unsigned long creator, int prefid, int backup, - int version, PI_CONST void *databuf, size_t datasize)); - - /** @brief Require reboot of device after HotSync terminates - * - * @param sd Socket number - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ResetSystem PI_ARGS((int sd)); - -/*@}*/ - -/** @name Database access functions */ -/*@{*/ - /** @brief Read the database list from the device - * - * The database list can be read either one database at a time (slower), - * or passing ::dlpDBListMultiple in the @p flags member. Pass ::dlpDBListRAM - * in @p flags to get the list of databases in RAM, and ::dlpDBListROM to get - * the list of databases in ROM. You can mix flags to obtain the desired - * result. Passing ::dlpDBListMultiple will return several DBInfo - * structures at once (usually 20). Use (info->used / sizeof(DBInfo)) to - * know how many database information blocks were returned. - * For the next call, pass the last DBInfo->index value + 1 to start to - * the next database. @n @n - * When all the database informations have been retrieved, this function returns - * #PI_ERR_DLP_PALMOS and pi_palmos_error() returns #dlpErrNotFound. - * - * @param sd Socket number - * @param cardno Card number (should be 0) - * @param flags Flags (see #dlpDBList enum) - * @param start Index of first database to list (zero based) - * @param dblist Buffer filled with one or more DBInfo structure - * @return A negative value if an error occured or the DB list is exhausted (see pi-error.h) - * - */ - extern PI_ERR dlp_ReadDBList - PI_ARGS((int sd, int cardno, int flags, int start, - pi_buffer_t *dblist)); - - /** @brief Find a database by name - * - * Supported on Palm OS 3.0 (DLP 1.2) and later. - * - * @param sd Socket number - * @param cardno Memory card number (usually 0) - * @param dbname Database name - * @param localid If not NULL, on return contains the LocalID of the database if it was found - * @param dbhandle If not NULL, on return contains the handle of the database if it is currently open - * @param dbInfo If not NULL, on return contains information about the database - * @param dbSize If not NULL, on return contains information about the database size - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_FindDBByName - PI_ARGS((int sd, int cardno, PI_CONST char *dbname, unsigned long *localid, int *dbhandle, - struct DBInfo *dbInfo, struct DBSizeInfo *dbSize)); - - /** @brief Get information about an open database - * - * Supported on Palm OS 3.0 (DLP 1.2) and later. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param cardno If not NULL, on return contains the cardno of the memory card the database resides on - * @param localid If not NULL, on return contains the LocalID of the database - * @param dbInfo If not NULL, on return contains information about the database - * @param dbSize If not NULL, on return contains information about the database size - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_FindDBByOpenHandle - PI_ARGS((int sd, int dbhandle, int *cardno, unsigned long *localid, - struct DBInfo *dbInfo, struct DBSizeInfo *dbSize)); - - /** @brief Find databases by type and/or creator - * - * Supported on Palm OS 3.0 (DLP 1.2) and later. To look for multiple databases, - * make a first call with @p start set to 1, then subsequent calls with @p start set to 0 - * until no more database is found. - * - * @param sd Socket number - * @param type If not 0, type code to look for - * @param creator If not 0, creator code to look for - * @param start If set, start a new search - * @param latest If set, returns the database with the latest version if there are several identical databases - * @param cardno If not NULL, on return contains the memory card number the database resides on - * @param localid If not NULL, on return contains the LocalID of the database - * @param dbhandle If not NULL, on return contains the handle of the database if it is currently open - * @param dbInfo If not NULL, on return contains information about the database - * @param dbSize If not NULL, on return contains information about the database size - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_FindDBByTypeCreator - PI_ARGS((int sd, unsigned long type, unsigned long creator, int start, - int latest, int *cardno, unsigned long *localid, int *dbhandle, - struct DBInfo *dbInfo, struct DBSizeInfo *dbSize)); - - /** @brief Look for a database on the device - * - * This function does not match any DLP layer function, but is - * intended as a shortcut for programs looking for databases. It - * uses a fairly byzantine mechanism for ordering the RAM databases - * before the ROM ones. You must feed the @a index slot from the - * returned info in @p start the next time round. - * - * @param sd Socket number - * @param cardno Card number (should be 0) - * @param start Index of first database to list (zero based) - * @param dbname If not NULL, look for a database with this name - * @param type If not 0, matching database must have this type - * @param creator If not 0, matching database must have this creator code - * @param OUTPUT Returned database information on success - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_FindDBInfo - PI_ARGS((int sd, int cardno, int start, PI_CONST char *dbname, - unsigned long type, unsigned long creator, - struct DBInfo *OUTPUT)); - - /** @brief Open a database on the Palm. - * - * @param sd Socket number - * @param cardno Card number (should be 0) - * @param mode Open mode (see #dlpOpenFlags enum) - * @param dbname Database name - * @param dbhandle Returned database handle to use if other calls like dlp_CloseDB() - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_OpenDB - PI_ARGS((int sd, int cardno, int mode, PI_CONST char *dbname, - int *dbhandle)); - - /** @brief Close an opened database - * - * @param sd Socket number - * @param dbhandle The DB handle returned by dlp_OpenDB() - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_CloseDB PI_ARGS((int sd, int dbhandle)); - - /** @brief Close all opened databases - * - * @param sd Socket number - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_CloseDB_All PI_ARGS((int sd)); - - /** @brief Delete an existing database from the device - * - * @param sd Socket number - * @param cardno Card number (should be 0) - * @param dbname Database name - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_DeleteDB - PI_ARGS((int sd, int cardno, PI_CONST char *dbname)); - - /** @brief Create database on the device - * - * After creation, the database is open and ready for use. You should - * call dlp_CloseDB() once you're done with the database. - * - * @param sd Socket number - * @param creator Creator code for the new database (four-char code) - * @param type Type code for the new database (four-char code) - * @param cardno Card number (should be 0) - * @param flags Database flags (see #dlpDBFlags enum) - * @param version Database version number - * @param dbname Database name - * @param dbhandle On return, DB handle to pass to other calls like dlp_CloseDB() - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_CreateDB - PI_ARGS((int sd, unsigned long creator, unsigned long type, - int cardno, int flags, unsigned int version, - PI_CONST char *dbname, int *dbhandle)); - - /** @brief Return the number of records in an opened database. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param numrecs On return, number of records in the database - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadOpenDBInfo - PI_ARGS((int sd, int dbhandle, int *numrecs)); - - /** @brief Change information for an open database - * - * Supported on Palm OS 3.0 (DLP 1.2) and later. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param flags Flags to set for this database (see #dlpDBFlags enum) - * @param clearFlags Flags to clear for this database (see #dlpDBFlags enum) - * @param version Version of this database - * @param createDate Creation date of this database - * @param modifyDate Modification date of this database (use @c 0x83DAC000 to unset) - * @param backupDate Last backup date of this database (use @c 0x83DAC000 to unset) - * @param type Database type code (four-char code) - * @param creator Database creator code (four-char code) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_SetDBInfo - PI_ARGS((int sd, int dbhandle, int flags, int clearFlags, unsigned int version, - time_t createDate, time_t modifyDate, time_t backupDate, - unsigned long type, unsigned long creator)); - - /** @brief Delete a category from a database - * - * Any record in that category will be moved to the Unfiled category. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param category Category to delete - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_DeleteCategory - PI_ARGS((int sd, int dbhandle, int category)); - - /** @brief Move all records from a category to another category - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param fromcat Category to move from (0-15) - * @param tocat Category to move to (0-15) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_MoveCategory - PI_ARGS((int sd, int dbhandle, int fromcat, int tocat)); - - /** @brief Read a database's AppInfo block - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param offset Offset to start reading from (0 based) - * @param reqbytes Number of bytes to read (pass -1 to read all data from @p offset to the end of the AppInfo block) - * @param retbuf Buffer allocated using pi_buffer_new(). On return contains the data from the AppInfo block - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadAppBlock - PI_ARGS((int sd, int dbhandle, int offset, int reqbytes, - pi_buffer_t *retbuf)); - - /** @brief Write a database's AppInfo block - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param databuf Pointer to the new AppInfo data. - * @param datasize Length of the new AppInfo data. If 0, the AppInfo block is removed. - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_WriteAppBlock - PI_ARGS((int sd, int dbhandle, PI_CONST void *databuf, size_t datasize)); - - /** @brief Read a database's SortInfo block - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param offset Offset to start reading from (0 based) - * @param reqbytes Number of bytes to read (pass -1 to read all data from @p offset to the end of the SortInfo block) - * @param retbuf Buffer allocated using pi_buffer_new(). On return contains the data from the SortInfo block - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadSortBlock - PI_ARGS((int sd, int dbhandle, int offset, int reqbytes, - pi_buffer_t *retbuf)); - - /** @brief Write a database's SortInfo block - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param databuf Pointer to the new SortInfo data. - * @param datasize Length of the new SortInfo data. If 0, the SortInfo block is removed. - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_WriteSortBlock - PI_ARGS((int sd, int dbhandle, PI_CONST void *databuf, - size_t datasize)); - - /** @brief Clean up a database by removing deleted/archived records - * - * Delete all records in the opened database which are marked as - * archived or deleted. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_CleanUpDatabase PI_ARGS((int sd, int dbhandle)); - - /** @brief Reset dirty record flags, update sync time - * - * For record databases, reset all dirty flags. For both record and - * resource databases, set the last sync time to now. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ResetSyncFlags PI_ARGS((int sd, int dbhandle)); - - /** @brief Reset the nextRecord position used in dlp_ReadNextRecInCategory() - * - * This resets the nextRecord both internally and on the device. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ResetDBIndex PI_ARGS((int sd, int dbhandle)); - - /** @brief Read the list of record IDs from an open database - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param sort If non-zero, the on-device application with the same DB creator will be called to re-sort the records prior to returning the list - * @param start Index of first record ID to return (zero based) - * @param max Maximum number of record IDs to return - * @param recuids On return, @p count record UIDs - * @param count On return, the number of record IDs found in @p IDs - * @return A negative value if an error occured (see pi-error.h) - */ -#ifndef SWIG /* bindings provide a native implementation */ - extern PI_ERR dlp_ReadRecordIDList - PI_ARGS((int sd, int dbhandle, int sort, int start, int max, - recordid_t *recuids, int *count)); -#endif - - /** @brief Read a record using its unique ID - * - * Read a record identified by its unique ID. Make sure you only - * request records that effectively exist in the database (use - * dlp_ReadRecordIDList() to retrieve the unique IDs of all records - * in the database). - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param recuid Record unique ID - * @param retbuf If not NULL, a buffer allocated using pi_buffer_new(). On return, contains the record contents - * @param recindex If not NULL, contains the record index on return. - * @param recattrs If not NULL, contains the record attributes on return. - * @param category If not NULL, contains the record category on return. - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadRecordById - PI_ARGS((int sd, int dbhandle, recordid_t recuid, pi_buffer_t *retbuf, - int *recindex, int *recattrs, int *category)); - - /** @brief Read a record using its index - * - * Read a record by record index (zero-based). Make sure you only - * request records within the bounds of database records - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param recindex Record index (zero based) - * @param retbuf If not NULL, a buffer allocated using pi_buffer_new(). On return, contains the record contents - * @param recuid If not NULL, contains the record UID on return. - * @param recattrs If not NULL, contains the record attributes on return. - * @param category If not NULL, contains the record category on return. - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadRecordByIndex - PI_ARGS((int sd, int dbhandle, int recindex, pi_buffer_t *retbuf, - recordid_t *recuid, int *recattrs, int *category)); - - /** @brief Iterate through modified records in database - * - * Return subsequent modified records on each call. Use dlp_ResetDBIndex() - * prior to starting iterations. Once all the records have been seen, - * this function returns PI_ERR_DLP_PALMOS and pi_palmos_error() returns - * #dlpErrNotFound. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param retbuf If not NULL, a buffer created using pi_buffer_new(). Buffer is cleared first using pi_buffer_clear(). On return, contains the record data - * @param recuid If not NULL, contains the record unique ID on return - * @param recindex If not NULL, contains the record index on return - * @param recattrs If not NULL, contains the record attributes on return (see #dlpRecAttributes enum) - * @param category If not NULL, contains the record category on return - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadNextModifiedRec - PI_ARGS((int sd, int dbhandle, pi_buffer_t *retbuf, recordid_t *recuid, - int *recindex, int *recattrs, int *category)); - - /** @brief Iterate through modified records in category - * - * Return subsequent modified records on each call. Use dlp_ResetDBIndex() - * prior to starting iterations. Once all the records have been seen, - * this function returns PI_ERR_DLP_PALMOS and pi_palmos_error() returns - * #dlpErrNotFound. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param category The category to iterate into - * @param retbuf If not NULL, a buffer created using pi_buffer_new(). Buffer is cleared first using pi_buffer_clear(). On return, contains the record data - * @param recuid If not NULL, contains the record unique ID on return - * @param recindex If not NULL, contains the record index on return - * @param recattrs If not NULL, contains the record attributes on return (see #dlpRecAttributes enum) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadNextModifiedRecInCategory - PI_ARGS((int sd, int dbhandle, int category, pi_buffer_t *retbuf, - recordid_t *recuid, int *recindex, int *recattrs)); - - /** @brief Iterate through records in category - * - * Return subsequent records on each call. Use dlp_ResetDBIndex() - * prior to starting iterations. Once all the records have been seen, - * this function returns PI_ERR_DLP_PALMOS and pi_palmos_error() returns - * #dlpErrNotFound. - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param category The category to iterate into - * @param retbuf If not NULL, a buffer created using pi_buffer_new(). Buffer is cleared first using pi_buffer_clear(). On return, contains the record data - * @param recuid If not NULL, contains the record unique ID on return - * @param recindex If not NULL, contains the record index on return - * @param recattrs If not NULL, contains the record attributes on return (see #dlpRecAttributes enum) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadNextRecInCategory - PI_ARGS((int sd, int dbhandle, int category, pi_buffer_t *retbuf, - recordid_t *recuid, int *recindex, int *recattrs)); - - /** @brief Create a new record in a database - * - * Use this call to add records to a database. On DLP 1.4 and later, you can create records - * bigger than 64k. Set the record ID to 0 to have the device generate the record ID itself, - * or assign a record ID of your own. Read Palm's documentation for information about - * record IDs, as there is a way to indicate which records were created by the desktop and - * which ones were created by the device applications. - * - * If you pass -1 as the data length, the function will treat the data as a string and use - * strlen(data)+1 as the data length (that is, the string is written including the - * terminating nul character). - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param flags Record attributes (see #dlpRecAttributes enum) - * @param recuid Record ID of the new record. If 0, device will generate a new record ID for this record. - * @param catid Category of the new record - * @param databuf Ptr to record data - * @param datasize Record data length - * @param newrecuid On return, record ID that was assigned to this record - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_WriteRecord - PI_ARGS((int sd, int dbhandle, int flags, recordid_t recuid, - int catid, PI_CONST void *databuf, size_t datasize, - recordid_t *newrecuid)); - - /** @brief Delete an existing record from a database - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param all If set, ALL records are deleted from the database. - * @param recuid Record ID of record to delete if @p all == 0. - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_DeleteRecord - PI_ARGS((int sd, int dbhandle, int all, recordid_t recuid)); - - /** @brief Read a resource identified by its type and ID - * - * @note To read resources larger than 64K, you should use dlp_ReadResourceByIndex(). - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param type Type code for the resource (four-char code) - * @param resid Resource ID - * @param retbuf If not NULL, a buffer allocated using pi_buffer_new(). On return, contains the resource contents - * @param resindex If not NULL, on return contains the resource index - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadResourceByType - PI_ARGS((int sd, int dbhandle, unsigned long type, int resid, - pi_buffer_t *retbuf, int *resindex)); - - /** @brief Read a resource identified by its resource index - * - * This function supports reading resources larger than 64k on - * DLP 1.4 and later (Palm OS 5.2 and later). - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param resindex Resource index - * @param retbuf If not NULL, a buffer allocated using pi_buffer_new(). On return, contains the resource contents - * @param restype If not NULL, on return contains the resource type - * @param resid If not NULL, on return contains the resource ID - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ReadResourceByIndex - PI_ARGS((int sd, int dbhandle, unsigned int resindex, pi_buffer_t *retbuf, - unsigned long *restype, int *resid)); - - /** @brief Create a new resource of overwrite an existing one - * - * This function supports writing resources larger than 64k on - * DLP 1.4 and later (Palm OS 5.2 and later). - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param restype Resource type (four-char code) - * @param resid Resource ID - * @param databuf Ptr to resource data - * @param datasize Length of resource data to write - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_WriteResource - PI_ARGS((int sd, int dbhandle, unsigned long restype, int resid, - PI_CONST void *databuf, size_t datasize)); - - /** @brief Delete a resource or all resources from a resource file - * - * @param sd Socket number - * @param dbhandle Open database handle, obtained from dlp_OpenDB() - * @param all If set, all resources are removed from this database (@p restype and @p resid are ignored) - * @param restype Resource type (four-char code) - * @param resid Resource ID - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_DeleteResource - PI_ARGS((int sd, int dbhandle, int all, unsigned long restype, - int resid)); -/*@}*/ - -/** @name Expansion manager functions */ -/*@{*/ - /** @brief Enumerate expansion slots - * - * Supported on Palm OS 4.0 and later. Expansion slots are physical slots - * present on the device. To check whether a card is inserted in a slot, - * use dlp_ExpCardPresent(). - * - * @param sd Socket number - * @param numslots On input, maximum number of slots that can be returned in the slotRefs array. On return, the actual number of slot references returned in @p slotRefs. - * @param slotrefs On return, @p numSlots slot references - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ExpSlotEnumerate - PI_ARGS((int sd, int *numslots, int *slotrefs)); - - /** @brief Checks whether a card is inserted in a slot - * - * Supported on Palm OS 4.0 and later. Returns >=0 if a card - * is inserted in the slot. - * - * @param sd Socket number - * @param slotref The slot reference as returned by dlp_ExpSlotEnumerate(). - * @return A negative value if an error occured (see pi-error.h), >=0 if a card is inserted - */ - extern PI_ERR dlp_ExpCardPresent - PI_ARGS((int sd, int slotref)); - - /** @brief Get information about a removable card inserted in an expansion slot - * - * Supported on Palm OS 4.0 and later. The info strings are returned in a - * single malloc()'ed buffer as a suite of nul-terminated string, one - * after the other. - * - * @param sd Socket number - * @param slotref The slot reference as returned by dlp_ExpSlotEnumerate(). - * @param expflags If not NULL, the card flags (see #dlpExpCardCapabilities enum) - * @param numstrings On return, the number of strings found in the @p strings array - * @param strings If not NULL, ptr to a char*. If there are strings to return, this function allocates a buffer to hold the strings. You are responsible for free()'ing the buffer once you're done with it. - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ExpCardInfo - PI_ARGS((int sd, int slotref, unsigned long *expflags, - int *numstrings, char **strings)); - - /** @brief Return the type of media supported by an expansion slot - * - * Supported on Palm OS 5.2 and later (DLP 1.4 and later). - * - * @param sd Socket number - * @param slotref The slot reference as returned by dlp_ExpSlotEnumerate(). - * @param mediatype On return, the media type - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_ExpSlotMediaType - PI_ARGS((int sd, int slotref, unsigned long *mediatype)); -/*@}*/ - -/** @name VFS manager functions */ -/*@{*/ - /** @brief Returns a list of connected VFS volumes - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param numvols On input, the maximum number of volume references that can be returned. On output, the actual number of volume references - * @param volrefs On output, @p numVols volume references - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSVolumeEnumerate - PI_ARGS((int sd, int *numvols, int *volrefs)); - - /** @brief Returns information about a VFS volume - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param volinfo On return, volume information - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSVolumeInfo - PI_ARGS((int sd, int volref, struct VFSInfo *volinfo)); - - /** @brief Return the label (name) of a VFS volume - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param len On input, the maximum size of the name buffer. On output, the name length (including the ending nul byte) - * @param name On output, the nul-terminated volume name - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSVolumeGetLabel - PI_ARGS((int sd, int volref, int *len, char *name)); - - /** @brief Change the label (name) of a VFS volume - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param name New volume name - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSVolumeSetLabel - PI_ARGS((int sd, int volref, PI_CONST char *name)); - - /** @brief Return the total and used size of a VFS volume - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param usedbytes On return, number of bytes used on the volume - * @param totalbytes On return, total size of the volume in bytes - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSVolumeSize - PI_ARGS((int sd, int volref, long *usedbytes, long *totalbytes)); - - /** @brief Format a VFS volume - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fmtflags Format flags (undocumented for now) - * @param fsLibRef File system lib ref (undocumented for now) - * @param param Slot mount parameters (undocumented for now) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSVolumeFormat - PI_ARGS((int sd, unsigned char fmtflags, int fsLibRef, - struct VFSSlotMountParam *param)); - - /** @brief Get the default storage directory for a given file type - * - * Supported on Palm OS 4.0 and later. Return the default directory - * for a file type. File types as expressed as MIME types, for - * example "image/jpeg", or as a simple file extension (i.e. ".jpg") - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param name MIME type to get the default directory for - * @param dir A buffer to hold the default path - * @param len On input, the length of the @p dir buffer. On return, contains the length of the path string (including the nul terminator) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSGetDefaultDir - PI_ARGS((int sd, int volref, PI_CONST char *name, - char *dir, int *len)); - - /** @brief Iterate through the entries in a directory - * - * Supported on Palm OS 4.0 and later. At the beginning you set - * @p dirIterator to #vfsIteratorStart, then call this function - * repeatedly until it returns an error code of the iterator becomes - * #vfsIteratorStop. - * - * @bug On some early OS 5 devices like Tungsten T and Sony NX70, NX73 this - * call crashes the device. This has been confirmed to be a bug in HotSync on - * the device, as tests showed that a regular HotSync conduit does crash the - * device with this call too. - * - * @param sd Socket number - * @param dirref Directory reference obtained from dlp_VFSFileOpen() - * @param diriterator Ptr to an iterator. Start with #vfsIteratorStart - * @param maxitems On input, the max number of VFSDirInfo structures stored in @p dirItems. On output, the actual number of items. - * @param diritems Preallocated array that contains a number of VFSDirInfo structures on return. - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSDirEntryEnumerate - PI_ARGS((int sd, FileRef dirref, unsigned long *diriterator, - int *maxitems, struct VFSDirInfo *diritems)); - - /** @brief Create a new directory on a VFS volume - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param path Full path for the directory to create - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSDirCreate - PI_ARGS((int sd, int volref, PI_CONST char *path)); - - /** @brief Import a VFS file to a database on the handheld - * - * Supported on Palm OS 4.0 and later. The file is converted to a - * full fledged database and stored in the handheld's RAM. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param pathname Path of the file to transfer to the handheld - * @param cardno On return, card number the database was created on (usually 0) - * @param localid On return, LocalID of the database that was created - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSImportDatabaseFromFile - PI_ARGS((int sd, int volref, PI_CONST char *pathname, - int *cardno, unsigned long *localid)); - - /** @brief Export a database to a VFS file - * - * Supported on Palm OS 4.0 and later. The database is converted to a - * .prc, .pdb or .pqa file on the VFS volume. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param pathname Path of the file to create on the VFS volume - * @param cardno Card number the database resides on (usually 0) - * @param localid LocalID of the database to export - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSExportDatabaseToFile - PI_ARGS((int sd, int volref, PI_CONST char *pathname, - int cardno, unsigned int localid)); - - /** @brief Create a new file on a VFS volume - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param pathname Full path of the file to create - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileCreate - PI_ARGS((int sd, int volref, PI_CONST char *pathname)); - - /** @brief Open an existing file on a VFS volume - * - * Supported on Palm OS 4.0 and later. On some devices, it is required to open the - * file using the #dlpOpenReadWrite mode to be able to write to it (using - * #dlpOpenWrite is not enough). - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param path Full path of the file to open - * @param mode Open mode flags (see #dlpVFSOpenFlags enum) - * @param fileref On return, file reference to the open file - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileOpen - PI_ARGS((int sd, int volref, PI_CONST char *path, int mode, - FileRef *fileref)); - - /** @brief Close an open VFS file - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File reference obtained from dlp_VFSFileOpen() - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileClose - PI_ARGS((int sd, FileRef fileref)); - - /** @brief Write data to an open file - * - * Supported on Palm OS 4.0 and later. Will return the number of bytes - * written if successful. - * - * @param sd Socket number - * @param fileref File reference obtained from dlp_VFSFileOpen() - * @param databuf Ptr to the data to write - * @param datasize Length of the data to write - * @return A negative value if an error occured (see pi-error.h), the number of bytes written otherwise. - */ - extern PI_ERR dlp_VFSFileWrite - PI_ARGS((int sd, FileRef fileref, PI_CONST void *databuf, size_t datasize)); - - /** @brief Read data from an open file - * - * Supported on Palm OS 4.0 and later. Will return the total number of bytes - * actually read. - * - * @param sd Socket number - * @param fileref File reference obtained from dlp_VFSFileOpen() - * @param retbuf Buffer allocated using pi_buffer_new(). Buffer is being emptied first with pi_buffer_clear(). On return contains the data read from the file. - * @param reqbytes Number of bytes to read from the file. - * @return A negative value if an error occured (see pi-error.h), or the total number of bytes read - */ - extern PI_ERR dlp_VFSFileRead - PI_ARGS((int sd, FileRef fileref, pi_buffer_t *retbuf, size_t reqbytes)); - - /** @brief Delete an existing file from a VFS volume - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param pathname Full access path to the file to delete - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileDelete - PI_ARGS((int sd, int volref, PI_CONST char *pathname)); - - /** @brief Rename an existing file - * - * Supported on Palm OS 4.0 and later. - * - * @note This function can NOT be used to move a file from one place - * to another. You can only rename a file that will stay in the same - * directory. - * - * @param sd Socket number - * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) - * @param pathname Full access path to the file to rename - * @param newname New file name, without the rest of the access path - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileRename - PI_ARGS((int sd, int volref, PI_CONST char *pathname, - PI_CONST char *newname)); - - /** @brief Checks whether the current position is at the end of file - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File reference obtained from dlp_VFSFileOpen() - * @return A negative value if an error occured (see pi-error.h). 0 if not at EOF, >0 if at EOF. - */ - extern PI_ERR dlp_VFSFileEOF - PI_ARGS((int sd, FileRef fileref)); - - /** @brief Return the current seek position in an open file - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File reference obtained from dlp_VFSFileOpen() - * @param position On return, current absolute position in the file - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileTell - PI_ARGS((int sd, FileRef fileref, int *position)); - - /** @brief Return the attributes of an open file - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File reference obtained from dlp_VFSFileOpen() - * @param fileattrs On return, file attributes (see #dlpVFSFileAttributeConstants enum) - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileGetAttributes - PI_ARGS((int sd, FileRef fileref, unsigned long *fileattrs)); - - /** @brief Change the attributes of an open file - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File reference obtained from dlp_VFSFileOpen() - * @param fileattrs n-New file attributes (see #dlpVFSFileAttributeConstants enum) - * @return A negative value if an error occured (see pi-error.h). - */ - extern PI_ERR dlp_VFSFileSetAttributes - PI_ARGS((int sd, FileRef fileref, unsigned long fileattrs)); - - /** @brief Return one of the dates associated with an open file or directory - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File or directory reference obtained from dlp_VFSFileOpen() - * @param which The date you want (see #dlpVFSDateConstants enum) - * @param date On return, the requested date - * @return A negative value if an error occured (see pi-error.h). - */ - extern PI_ERR dlp_VFSFileGetDate - PI_ARGS((int sd, FileRef fileref, int which, time_t *date)); - - /** @brief Change one of the dates for an open file or directory - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File or directory reference obtained from dlp_VFSFileOpen() - * @param which The date you want to change (see #dlpVFSDateConstants enum) - * @param date The new date to set - * @return A negative value if an error occured (see pi-error.h). - */ - extern PI_ERR dlp_VFSFileSetDate - PI_ARGS((int sd, FileRef fileref, int which, time_t date)); - - /** @brief Change the current seek position in an open file - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File or directory reference obtained from dlp_VFSFileOpen() - * @param origin Where to seek from (see #dlpVFSSeekConstants enum) - * @param offset Seek offset - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileSeek - PI_ARGS((int sd, FileRef fileref, int origin, int offset)); - - /** @brief Resize an open file - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File or directory reference obtained from dlp_VFSFileOpen() - * @param newsize New file size - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileResize - PI_ARGS((int sd, FileRef fileref, int newsize)); - - /** @brief Return the size of an open file - * - * Supported on Palm OS 4.0 and later. - * - * @param sd Socket number - * @param fileref File or directory reference obtained from dlp_VFSFileOpen() - * @param size On return, the actual size of the file - * @return A negative value if an error occured (see pi-error.h) - */ - extern PI_ERR dlp_VFSFileSize - PI_ARGS((int sd, FileRef fileref, int *size)); -/*@}*/ - -#ifdef __cplusplus -} -#endif -#endif /*_PILOT_DLP_H_*/ diff --git a/pilot-link/pi-error.h b/pilot-link/pi-error.h deleted file mode 100644 index cb30b8f11..000000000 --- a/pilot-link/pi-error.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * $Id: pi-error.h,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * pi-error.h: definitions for errors returned by the SOCKET, DLP and - * FILE layers - * - * Copyright (c) 2004-2005, Florent Pillet. - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef _PILOT_ERROR_H_ -#define _PILOT_ERROR_H_ - -/** @file pi-error.h - * @brief Error definitions for the errors returned by libpisock's dlp_XXX functions. - * - * Most dlp_XXX functions return a value that is >= if the function - * succeeded, or < 0 if there was an error. The error code can be directly - * tested, and can also be retrieved using pi_error(). If the error code is - * #PI_ERR_DLP_PALMOS, you should read the error code returned by the device - * using pi_palmos_error(). - * - * @note These error codes are tailored to not conflict with dlpErr* codes - * defined in dlp.h, and which can be checked using pi_palmos_error() - * - */ - -/** @brief Type definition for error returned by various function. - * - * The reason we have a typedef is mostly for swig-generated bindings to - * properly handle result codes - */ - -/**< Type for result codes returned by various library functions (mainly for swig-generated bindings) */ -typedef int PI_ERR; - -/** @brief Definition of errors returned by various libpisock functions */ -enum dlpErrorDefinitions { - /* PROTOCOL level errors */ - PI_ERR_PROT_ABORTED = -100, /**< aborted by other end */ - PI_ERR_PROT_INCOMPATIBLE = -101, /**< can't talk with other end */ - PI_ERR_PROT_BADPACKET = -102, /**< bad packet (used with serial protocols) */ - - /* SOCKET level errors */ - PI_ERR_SOCK_DISCONNECTED = -200, /**< connection has been broken */ - PI_ERR_SOCK_INVALID = -201, /**< invalid protocol stack */ - PI_ERR_SOCK_TIMEOUT = -202, /**< communications timeout (but link not known as broken) */ - PI_ERR_SOCK_CANCELED = -203, /**< last data transfer was canceled */ - PI_ERR_SOCK_IO = -204, /**< generic I/O error */ - PI_ERR_SOCK_LISTENER = -205, /**< socket can't listen/accept */ - - /* DLP level errors */ - PI_ERR_DLP_BUFSIZE = -300, /**< provided buffer is not big enough to store data */ - PI_ERR_DLP_PALMOS = -301, /**< a non-zero error was returned by the device */ - PI_ERR_DLP_UNSUPPORTED = -302, /**< this DLP call is not supported by the connected handheld */ - PI_ERR_DLP_SOCKET = -303, /**< invalid socket */ - PI_ERR_DLP_DATASIZE = -304, /**< requested transfer with data block too large (>64k) */ - PI_ERR_DLP_COMMAND = -305, /**< command error (the device returned an invalid response) */ - - /* FILE level error */ - PI_ERR_FILE_INVALID = -400, /**< invalid prc/pdb/pqa/pi_file file */ - PI_ERR_FILE_ERROR = -401, /**< generic error when reading/writing file */ - PI_ERR_FILE_ABORTED = -402, /**< file transfer was aborted by progress callback, see pi_file_retrieve(), pi_file_install(), pi_file_merge() */ - PI_ERR_FILE_NOT_FOUND = -403, /**< record or resource not found */ - PI_ERR_FILE_ALREADY_EXISTS = -404, /**< a record with same UID or resource with same type/ID already exists */ - - /* GENERIC errors */ - PI_ERR_GENERIC_MEMORY = -500, /**< not enough memory */ - PI_ERR_GENERIC_ARGUMENT = -501, /**< invalid argument(s) */ - PI_ERR_GENERIC_SYSTEM = -502 /**< generic system error */ -}; - -/** @name libpisock error management macros */ -/*@{*/ - #define IS_PROT_ERR(error) ((error)<=-100 && (error)>-200) /**< Check whether the error code is at protocol level */ - #define IS_SOCK_ERR(error) ((error)<=-200 && (error)>-300) /**< Check whether the error code is at socket level */ - #define IS_DLP_ERR(error) ((error)<=-300 && (error)>-400) /**< Check whether the error code is at DLP level */ - #define IS_FILE_ERR(error) ((error)<=-400 && (error)>-500) /**< Check whether the error code os a file error */ - #define IS_GENERIC_ERR(error) ((error)<=-500 && (error)>-600) /**< Check whether the error code is a generic error */ -/*@}*/ - -#endif diff --git a/pilot-link/pi-file.c b/pilot-link/pi-file.c deleted file mode 100644 index e11ec69ab..000000000 --- a/pilot-link/pi-file.c +++ /dev/null @@ -1,1534 +0,0 @@ -/* - * $Id: pi-file.c,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * Pilot File Interface Library - * Pace Willisson December 1996 - * Additions by Kenneth Albanowski - * Additions by Florent Pillet - * - * This is free software, licensed under the GNU Library Public License V2. - * See the file COPYING.LIB for details. - * - * the following is extracted from the combined wisdom of - * PDB by Kevin L. Flynn - * install-prc by Brian J. Swetland, D. Jeff Dionne and Kenneth Albanowski - * makedoc7 by Pat Beirne, - * and the include files from the pilot SDK - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -// #include - -#include "pi-debug.h" -#include "pi-source.h" -#include "pi-file.h" -#include "pi-error.h" - -#undef FILEDEBUG -#define pi_mktag(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4)) - -/* - header: - 32 name - 2 flags - 2 version - 4 creation time - 4 modification time - 4 backup time - 4 modification number - 4 app info offset - 4 sort info offset - 4 type - 4 creator - 4 uniq id seed (I think it is just garbage) - 4 next record list id (normally 0, or ptr to extended hdr) - 2 num records for this header - - Hypothetically plus 2 more bytes if an extended or perhaps secondary - header (not supported) (In practice, this value is never set, instead it - usually indicates a damaged file.) - - if the low bit of attr is on, then next thing is a list of resource entry - descriptors: - - resource entry header - 4 type - 2 id - 4 offset - - otherwise, if the low bit of attr is off, the next thing is a list of - record entry decriptors: - - record entry header - 4 offset - 1 record attributes - 3 unique id - - then two bytes of unknown purpose, \0\0 seems safe - - next, the app_info, if any, then the sort_info, if any - - then the space used the data. Every offset is an offset from the - beginning of the file, and will point until this area. Each block starts - at the given offset and ends at the beginning of the next block. The last - block ends at the end of the file. - */ - -#define PI_HDR_SIZE 78 -#define PI_RESOURCE_ENT_SIZE 10 -#define PI_RECORD_ENT_SIZE 8 - -/* Local prototypes */ -static int pi_file_close_for_write(pi_file_t *pf); -static void pi_file_free(pi_file_t *pf); -static int pi_file_find_resource_by_type_id(const pi_file_t *pf, unsigned long restype, int resid, int *resindex); -static pi_file_entry_t *pi_file_append_entry(pi_file_t *pf); -static int pi_file_set_rbuf_size(pi_file_t *pf, size_t size); - -/* this seems to work, but what about leap years? */ -/*#define PILOT_TIME_DELTA (((unsigned)(1970 - 1904) * 365 * 24 * 60 * 60) + 1450800)*/ - -/* Exact value of "Jan 1, 1970 0:00:00 GMT" - "Jan 1, 1904 0:00:00 GMT" */ -#define PILOT_TIME_DELTA (unsigned)(2082844800) - - -/* FIXME: These conversion functions apply no timezone correction. UNIX uses - UTC for time_t's, while the Pilot uses local time for database backup - time and appointments, etc. It is not particularly simple to convert - between these in UNIX, especially since the Pilot's local time is - unknown, and if syncing over political boundries, could easily be - different then the local time on the UNIX box. Since the Pilot does not - know what timezone it is in, there is no unambiguous way to correct for - this. - - Worse, the creation date for a program is stored in the local time _of - the computer which did the final linking of that program_. Again, the - Pilot does not store the timezone information needed to reconstruct - where/when this was. - - A better immediate tack would be to dissect these into struct tm's, and - return those. - --KJA - */ -time_t -pilot_time_to_unix_time(unsigned long raw_time) -{ - return (time_t) (raw_time - PILOT_TIME_DELTA); -} - -unsigned long -unix_time_to_pilot_time(time_t t) -{ - return (unsigned long) ((unsigned long) t + PILOT_TIME_DELTA); -} - -pi_file_t -*pi_file_open(const char *name) -// *pi_file_openf(FILE *file) -{ - int i, - file_size; - - pi_file_t *pf; - struct DBInfo *ip; - pi_file_entry_t *entp; - - unsigned char buf[PI_HDR_SIZE]; - unsigned char *p; - off_t offset, app_info_offset = 0, sort_info_offset = 0; - - if ((pf = calloc(1, sizeof (pi_file_t))) == NULL) - return NULL; - - if ((pf->f = fopen(name, "rb")) == NULL) - goto bad; - - fseek(pf->f, 0, SEEK_END); - file_size = ftell(pf->f); - fseek(pf->f, 0, SEEK_SET); - - if (fread(buf, PI_HDR_SIZE, 1, pf->f) != (size_t) 1) { - LOG ((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE OPEN %s: can't read header\n", name)); - goto bad; - } - - p = buf; - ip = &pf->info; - - memcpy(ip->name, p, 32); - ip->flags = get_short(p + 32); - ip->miscFlags = dlpDBMiscFlagRamBased; - ip->version = get_short(p + 34); - ip->createDate = pilot_time_to_unix_time(get_long(p + 36)); - ip->modifyDate = pilot_time_to_unix_time(get_long(p + 40)); - ip->backupDate = pilot_time_to_unix_time(get_long(p + 44)); - ip->modnum = get_long(p + 48); - app_info_offset = get_long(p + 52); - sort_info_offset = get_long(p + 56); - ip->type = get_long(p + 60); - ip->creator = get_long(p + 64); - pf->unique_id_seed = get_long(p + 68); - - /* record list header */ - pf->next_record_list_id = get_long(p + 72); - pf->num_entries = get_short(p + 76); - - LOG ((PI_DBG_API, PI_DBG_LVL_INFO, - "FILE OPEN Name: '%s' Flags: 0x%4.4X Version: %d\n", - ip->name, ip->flags, ip->version)); - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - " Creation date: %s", ctime(&ip->createDate))); - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - " Modification date: %s", ctime(&ip->modifyDate))); - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - " Backup date: %s", ctime(&ip->backupDate))); - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - " Appinfo Size: %d Sortinfo Size: %d\n", - pf->app_info_size, pf->sort_info_size)); - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - " Type: '%s'", printlong(ip->type))); - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - " Creator: '%s' Seed: 0x%8.8lX\n", printlong(ip->creator), - pf->unique_id_seed)); - - if (pf->next_record_list_id != 0) { - LOG ((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE OPEN %s: this file is probably damaged\n", name)); - goto bad; - } - - if (ip->flags & dlpDBFlagResource) { - pf->resource_flag = 1; - pf->ent_hdr_size = PI_RESOURCE_ENT_SIZE; - } else { - pf->resource_flag = 0; - pf->ent_hdr_size = PI_RECORD_ENT_SIZE; - } - - if (pf->num_entries < 0) { - LOG ((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE OPEN %s: bad header\n", name)); - goto bad; - } - - offset = file_size; - - if (pf->num_entries) { - if ((pf->entries = - calloc((size_t)pf->num_entries, - sizeof *pf->entries)) == NULL) - goto bad; - - for (i = 0, entp = pf->entries; i < pf->num_entries; - i++, entp++) { - if (fread(buf, (size_t) pf->ent_hdr_size, 1, pf->f) - != (size_t) 1) - goto bad; - - p = buf; - if (pf->resource_flag) { - entp->type = get_long(p); - entp->resource_id = get_short(p + 4); - entp->offset = get_long(p + 6); - - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - "FILE OPEN Entry %d '%s' #%d @%X\n", i, - printlong(entp->type), entp->resource_id, - entp->offset)); - } else { - entp->offset = get_long(p); - entp->attrs = get_byte(p + 4); - entp->uid = get_treble(p + 5); - - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - "FILE OPEN Entry %d UID: " - "0x%8.8X Attrs: %2.2X Offset: @%X\n", i, - (int) entp->uid, entp->attrs, - entp->offset)); - } - } - - for (i = 0, entp = pf->entries + pf->num_entries - 1; - i < pf->num_entries; i++, entp--) { - entp->size = offset - entp->offset; - offset = entp->offset; - - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - "FILE OPEN Entry: %d Size: %d\n", - pf->num_entries - i - 1, entp->size)); - - if (entp->size < 0 || - (entp->offset + entp->size) > file_size) { - LOG ((PI_DBG_API, PI_DBG_LVL_DEBUG, - "FILE OPEN %s: Entry %d corrupt," - " giving up\n", - name, pf->num_entries - i - 1)); - goto bad; - } - } - } - - if (sort_info_offset) { - pf->sort_info_size = offset - sort_info_offset; - offset = sort_info_offset; - } - - if (app_info_offset) { - pf->app_info_size = offset - app_info_offset; - offset = app_info_offset; - } - - if (pf->app_info_size < 0 || - (sort_info_offset + pf->sort_info_size) > file_size || - pf->sort_info_size < 0 || - (app_info_offset + pf->app_info_size) > file_size) { - LOG ((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE OPEN %s: bad header " - "(app_info @ %d size %d, " - "sort_info @ %d size %d)\n", name, - app_info_offset, pf->app_info_size, - sort_info_offset, pf->sort_info_size)); - goto bad; - } - - if (pf->app_info_size == 0) - pf->app_info = NULL; - else { - if ((pf->app_info = - malloc((size_t) pf->app_info_size)) == NULL) - goto bad; - fseek(pf->f, (long)app_info_offset, SEEK_SET); - if (fread(pf->app_info, 1, (size_t) pf->app_info_size, pf->f) - != (size_t) pf->app_info_size) - goto bad; - } - - if (pf->sort_info_size == 0) - pf->sort_info = NULL; - else { - if ((pf->sort_info = malloc((size_t)pf->sort_info_size)) - == NULL) - goto bad; - fseek(pf->f, (long)sort_info_offset, SEEK_SET); - if (fread(pf->sort_info, 1, (size_t) pf->sort_info_size, - pf->f) != (size_t) pf->sort_info_size) - goto bad; - } - - return pf; - -bad: - pi_file_close(pf); - return NULL; -} - -int -pi_file_close(pi_file_t *pf) -{ - int err; - - if (!pf) - return PI_ERR_FILE_INVALID; - - if (pf->for_writing) - pf->err = pi_file_close_for_write(pf); - - err = pf->err; - - pi_file_free(pf); - - return err; -} - -void -pi_file_get_info(const pi_file_t *pf, struct DBInfo *infop) -{ - *infop = pf->info; -} - -void -pi_file_get_app_info(pi_file_t *pf, void **datap, size_t *sizep) -{ - *datap = pf->app_info; - *sizep = pf->app_info_size; -} - -void -pi_file_get_sort_info(pi_file_t *pf, void **datap, size_t *sizep) -{ - *datap = pf->sort_info; - *sizep = pf->sort_info_size; -} - -int -pi_file_read_resource_by_type_id(pi_file_t *pf, unsigned long restype, - int resid, void **bufp, size_t *sizep, - int *resindex) -{ - int i, - result; - - result = pi_file_find_resource_by_type_id(pf, restype, resid, &i); - if (!result) - return PI_ERR_FILE_NOT_FOUND; - if (resindex) - *resindex = i; - return pi_file_read_resource(pf, i, bufp, sizep, NULL, NULL); -} - -int -pi_file_type_id_used(const pi_file_t *pf, unsigned long restype, int resid) -{ - return pi_file_find_resource_by_type_id(pf, restype, resid, NULL); -} - -int -pi_file_read_resource(pi_file_t *pf, int i, - void **bufp, size_t *sizep, unsigned long *type, - int *idp) -{ - pi_file_entry_t *entp; - int result; - - if (pf->for_writing || !pf->resource_flag) - return PI_ERR_FILE_INVALID; - - if (i < 0 || i >= pf->num_entries) - return PI_ERR_GENERIC_ARGUMENT; - - entp = &pf->entries[i]; - - if (bufp) { - if ((result = pi_file_set_rbuf_size(pf, (size_t) entp->size)) < 0) - return result; - fseek(pf->f, pf->entries[i].offset, SEEK_SET); - if (fread(pf->rbuf, 1, (size_t) entp->size, pf->f) != - (size_t) entp->size) - return PI_ERR_FILE_ERROR; - *bufp = pf->rbuf; - } - - if (sizep) - *sizep = entp->size; - if (type) - *type = entp->type; - if (idp) - *idp = entp->resource_id; - - return 0; -} - -int -pi_file_read_record(pi_file_t *pf, int recindex, - void **bufp, size_t *sizep, int *recattrs, int *category, - recordid_t * recuid) -{ - int result; - pi_file_entry_t *entp; - - if (pf->for_writing || pf->resource_flag) - return PI_ERR_FILE_INVALID; - - if (recindex < 0 || recindex >= pf->num_entries) - return PI_ERR_GENERIC_ARGUMENT; - - entp = &pf->entries[recindex]; - - if (bufp) { - if ((result = pi_file_set_rbuf_size(pf, (size_t) entp->size)) < 0) { - LOG((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE READ_RECORD Unable to set buffer size!\n")); - return result; - } - - fseek(pf->f, pf->entries[recindex].offset, SEEK_SET); - - if (fread(pf->rbuf, 1, (size_t) entp->size, pf->f) != - (size_t) entp->size) { - LOG((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE READ_RECORD Unable to read record!\n")); - return PI_ERR_FILE_ERROR; - } - - *bufp = pf->rbuf; - } - - LOG ((PI_DBG_API, PI_DBG_LVL_INFO, - "FILE READ_RECORD Record: %d Bytes: %d\n", recindex, entp->size)); - - if (sizep) - *sizep = entp->size; - if (recattrs) - *recattrs = entp->attrs & 0xf0; - if (category) - *category = entp->attrs & 0xf; - if (recuid) - *recuid = entp->uid; - - return 0; -} - -int -pi_file_read_record_by_id(pi_file_t *pf, recordid_t uid, - void **bufp, size_t *sizep, int *idxp, int *attrp, - int *catp) -{ - int i; - struct pi_file_entry *entp; - - for (i = 0, entp = pf->entries; i < pf->num_entries; - i++, entp++) { - if (entp->uid == uid) { - if (idxp) - *idxp = i; - return (pi_file_read_record - (pf, i, bufp, sizep, attrp, catp, &uid)); - } - } - - return PI_ERR_FILE_NOT_FOUND; -} - -int -pi_file_id_used(const pi_file_t *pf, recordid_t uid) -{ - int i; - struct pi_file_entry *entp; - - for (i = 0, entp = pf->entries; i < pf->num_entries; i++, entp++) { - if (entp->uid == uid) - return 1; - } - return 0; -} - -pi_file_t * -pi_file_create(const char *name, const struct DBInfo *info) -{ - pi_file_t *pf = calloc(1, sizeof(pi_file_t)); - - if (pf == NULL) - return NULL; - - if ((pf->file_name = strdup(name)) == NULL) - goto bad; - - pf->for_writing = 1; - pf->info = *info; - - if (info->flags & dlpDBFlagResource) { - pf->resource_flag = 1; - pf->ent_hdr_size = PI_RESOURCE_ENT_SIZE; - } else { - pf->resource_flag = 0; - pf->ent_hdr_size = PI_RECORD_ENT_SIZE; - } - - pf->tmpbuf = pi_buffer_new(2048); - if (pf->tmpbuf == NULL) - goto bad; - - return (pf); - -bad: - pi_file_free(pf); - return NULL; -} - -int -pi_file_set_info(pi_file_t *pf, const struct DBInfo *ip) -{ - if (!pf->for_writing) - return PI_ERR_FILE_INVALID; - - if ((ip->flags & dlpDBFlagResource) != - (pf->info.flags & dlpDBFlagResource)) - return PI_ERR_FILE_INVALID; - - pf->info = *ip; - - return 0; -} - -int -pi_file_set_app_info(pi_file_t *pf, void *data, size_t size) -{ - void *p; - - if (!size) { - if (pf->app_info) - free(pf->app_info); - pf->app_info_size = 0; - return 0; - } - - if ((p = malloc(size)) == NULL) - return PI_ERR_GENERIC_MEMORY; - - memcpy(p, data, size); - - if (pf->app_info) - free(pf->app_info); - - pf->app_info = p; - pf->app_info_size = size; - - return 0; -} - -int -pi_file_set_sort_info(pi_file_t *pf, void *data, size_t size) -{ - void *p; - - if (!size) { - if (pf->sort_info) - free(pf->sort_info); - pf->sort_info_size = 0; - return 0; - } - - if ((p = malloc(size)) == NULL) - return PI_ERR_GENERIC_MEMORY; - - memcpy(p, data, size); - - if (pf->sort_info) - free(pf->sort_info); - - pf->sort_info = p; - pf->sort_info_size = size; - - return 0; -} - -int -pi_file_append_resource(pi_file_t *pf, void *data, size_t size, - unsigned long restype, int resid) -{ - pi_file_entry_t *entp; - - if (!pf->for_writing || !pf->resource_flag) - return PI_ERR_FILE_INVALID; - if (pi_file_type_id_used(pf, restype, resid)) - return PI_ERR_FILE_ALREADY_EXISTS; - - entp = pi_file_append_entry(pf); - if (entp == NULL) - return PI_ERR_GENERIC_MEMORY; - - if (size && pi_buffer_append(pf->tmpbuf, data, size) == NULL) { - pf->err = 1; - return PI_ERR_GENERIC_MEMORY; - } - - entp->size = size; - entp->type = restype; - entp->resource_id = resid; - - return size; -} - -int -pi_file_append_record(pi_file_t *pf, void *data, size_t size, - int recattrs, int category, recordid_t recuid) -{ - pi_file_entry_t *entp; - - if (!pf->for_writing || pf->resource_flag) - return PI_ERR_FILE_INVALID; - if (recuid && pi_file_id_used(pf, recuid)) - return PI_ERR_FILE_ALREADY_EXISTS; - - entp = pi_file_append_entry(pf); - if (entp == NULL) - return PI_ERR_GENERIC_MEMORY; - - if (size && pi_buffer_append(pf->tmpbuf, data, size) == NULL) { - pf->err = 1; - return PI_ERR_GENERIC_MEMORY; - } - - entp->size = size; - entp->attrs = (recattrs & 0xf0) | (category & 0xf); - entp->uid = recuid; - - return size; -} - -void -pi_file_get_entries(pi_file_t *pf, int *entries) -{ - *entries = pf->num_entries; -} - -#if XXX -int -pi_file_retrieve(pi_file_t *pf, int socket, int cardno, - progress_func report_progress) -{ - int db = -1, - result, - old_device = 0; - - unsigned int j; - - struct DBInfo dbi; - struct DBSizeInfo size_info; - - pi_buffer_t *buffer = NULL; - pi_progress_t progress; - - pi_reset_errors(socket); - memset(&size_info, 0, sizeof(size_info)); - memset(&dbi, 0, sizeof(dbi)); - - /* Try to get more info on the database to retrieve. Note that - * with some devices like the Tungsten T3 and shadowed databases - * like AddressDB, the size_info is -wrong-. It doesn't reflect - * the actual contents of the database except for the number of - * records. Also, this call doesn't work pre-OS 3. - */ - if ((result = dlp_FindDBByName(socket, cardno, pf->info.name, - NULL, NULL, &dbi, &size_info)) < 0) - { - if (result != PI_ERR_DLP_UNSUPPORTED) - goto fail; - old_device = 1; - } - - if ((result = dlp_OpenDB (socket, cardno, dlpOpenRead | dlpOpenSecret, - pf->info.name, &db)) < 0) - goto fail; - - buffer = pi_buffer_new (DLP_BUF_SIZE); - if (buffer == NULL) { - result = pi_set_error(socket, PI_ERR_GENERIC_MEMORY); - goto fail; - } - - if (old_device) { - int num_records; - if ((result = dlp_ReadOpenDBInfo(socket, db, &num_records)) < 0) - goto fail; - size_info.numRecords = num_records; - } - - memset(&progress, 0, sizeof(progress)); - progress.type = PI_PROGRESS_RECEIVE_DB; - progress.data.db.pf = pf; - progress.data.db.size = size_info; - - if (size_info.appBlockSize - || (dbi.miscFlags & dlpDBMiscFlagRamBased) - || old_device) { - /* what we're trying to do here is avoid trying to read an appBlock - * from a ROM file, because this crashes on several devices. - * Also, on several palmOne devices, the size info returned by the OS - * is absolutely incorrect. This happens with some system shadow files - * like AddressDB on T3, which actually do contain data and an appInfo - * block but the system tells us there's no appInfo and nearly no data, - * but still gives the accurate number of records. Seems to be bad - * structure shadows in PACE. - * In any case, the ultimate result is that: - * 1. On devices pre-OS 3, we do always try to read the appInfo block - * because dlp_FindDBByName() is unsupported so we can't find out if - * there's an appInfo block - * 2. On OS5+ devices, we're not sure that the appInfo size we have is - * accurate. But if we try reading an appInfo block in ROM it may - * crash the device - * 3. Therefore, we only try to read the appInfo block if we are - * working on a RAM file or we are sure that a ROM file has appInfo. - */ - result = dlp_ReadAppBlock(socket, db, 0, DLP_BUF_SIZE, buffer); - if (result > 0) { - pi_file_set_app_info(pf, buffer->data, (size_t)result); - progress.transferred_bytes += result; - if (report_progress && report_progress(socket, - &progress) == PI_TRANSFER_STOP) { - result = PI_ERR_FILE_ABORTED; - goto fail; - } - } - } - - if (pf->info.flags & dlpDBFlagResource) { - for (j = 0; j < size_info.numRecords; j++) { - int resource_id; - unsigned long type; - - if ((result = dlp_ReadResourceByIndex(socket, db, j, buffer, - &type, &resource_id)) < 0) - goto fail; - - if ((result = pi_file_append_resource (pf, buffer->data, buffer->used, - type, resource_id)) < 0) { - pi_set_error(socket, result); - goto fail; - } - - progress.transferred_bytes += buffer->used; - progress.data.db.transferred_records++; - - if (report_progress && report_progress(socket, - &progress) == PI_TRANSFER_STOP) { - result = pi_set_error(socket, PI_ERR_FILE_ABORTED); - goto fail; - } - } - } else for (j = 0; j < size_info.numRecords; j++) { - int attr, - category; - unsigned long resource_id; - - if ((result = dlp_ReadRecordByIndex(socket, db, j, buffer, &resource_id, &attr, - &category)) < 0) - goto fail; - - progress.transferred_bytes += buffer->used; - progress.data.db.transferred_records++; - - if (report_progress - && report_progress(socket, - &progress) == PI_TRANSFER_STOP) { - result = pi_set_error(socket, PI_ERR_FILE_ABORTED); - goto fail; - } - - /* There is no way to restore records with these - attributes, so there is no use in backing them up - */ - if (attr & - (dlpRecAttrArchived | dlpRecAttrDeleted)) - continue; - if ((result = pi_file_append_record(pf, buffer->data, buffer->used, - attr, category, resource_id)) < 0) { - pi_set_error(socket, result); - goto fail; - } - } - - pi_buffer_free(buffer); - - return dlp_CloseDB(socket, db); - -fail: - if (db != -1 && pi_socket_connected(socket)) { - int err = pi_error(socket); /* make sure we keep last error code */ - int palmoserr = pi_palmos_error(socket); - - dlp_CloseDB(socket, db); - - pi_set_error(socket, err); /* then restore it afterwards */ - pi_set_palmos_error(socket, palmoserr); - } - - if (buffer != NULL) - pi_buffer_free (buffer); - - if (result >= 0) { - /* one of our pi_file* calls failed */ - result = pi_set_error(socket, PI_ERR_FILE_ERROR); - } - return result; -} - -int -pi_file_install(pi_file_t *pf, int socket, int cardno, - progress_func report_progress) -{ - int db = -1, - j, - reset = 0, - flags, - version, - freeai = 0, - result, - err1, - err2; - size_t l, - size = 0; - void *buffer; - pi_progress_t progress; - - version = pi_version(socket); - - memset(&progress, 0, sizeof(progress)); - progress.type = PI_PROGRESS_SEND_DB; - progress.data.db.pf = pf; - progress.data.db.size.numRecords = pf->num_entries; - progress.data.db.size.dataBytes = pf->app_info_size; - progress.data.db.size.appBlockSize = pf->app_info_size; - progress.data.db.size.maxRecSize = pi_maxrecsize(socket); - - /* compute total size for progress reporting, and check that - either records are 64k or less, or the handheld can accept - large records. we do this prior to starting the install, - to avoid messing the device up if we have to fail. */ - for (j = 0; j < pf->num_entries; j++) { - result = (pf->info.flags & dlpDBFlagResource) ? - pi_file_read_resource(pf, j, 0, &size, 0, 0) : - pi_file_read_record(pf, j, 0, &size, 0, 0, 0); - if (result < 0) { - LOG((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE INSTALL can't read all records/resources\n")); - goto fail; - } - if (size > 65536 && version < 0x0104) { - LOG((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE INSTALL Database contains" - " record/resource over 64K!\n")); - goto fail; - } - progress.data.db.size.dataBytes += size; - } - - progress.data.db.size.totalBytes = - progress.data.db.size.dataBytes + - pf->ent_hdr_size * pf->num_entries + - PI_HDR_SIZE + 2; - - /* Delete DB if it already exists */ - dlp_DeleteDB(socket, cardno, pf->info.name); - - /* Set up DB flags */ - flags = pf->info.flags; - - /* Judd - 25Nov99 - Graffiti hack We want to make sure that these 2 - flags get set for this one */ - if (pf->info.creator == pi_mktag('g', 'r', 'a', 'f')) { - flags |= dlpDBFlagNewer; - flags |= dlpDBFlagReset; - } - - if (strcmp(pf->info.name, "Graffiti ShortCuts ") == 0) { - flags |= 0x8000; /* Rewrite an open DB */ - reset = 1; /* To be on the safe side */ - } - LOG((PI_DBG_API, PI_DBG_LVL_INFO, - "FILE INSTALL Name: %s Flags: %8.8X\n", pf->info.name, flags)); - - /* Create DB */ - if ((result = dlp_CreateDB - (socket, pf->info.creator, pf->info.type, cardno, flags, - pf->info.version, pf->info.name, &db)) < 0) { - int retry = 0; - - /* Judd - 25Nov99 - Graffiti hack - - The dlpDBFlagNewer specifies that if a DB is open and - cannot be deleted then it can be overwritten by a DB with - a different name. The creator ID of "graf" is what - really identifies a DB, not the name. We could call it - JimBob and the palm would still find it and use it. */ - - if (strcmp(pf->info.name, "Graffiti ShortCuts ") == 0) { - strcpy(pf->info.name, "Graffiti ShortCuts"); - retry = 1; - } else if (strcmp(pf->info.name, "Graffiti ShortCuts") == - 0) { - strcpy(pf->info.name, "Graffiti ShortCuts "); - retry = 1; - } else if (pf->info.creator == - pi_mktag('g', 'r', 'a', 'f')) { - /* Yep, someone has named it JimBob */ - strcpy(pf->info.name, "Graffiti ShortCuts"); - retry = 1; - } - - if (retry) { - /* Judd - 25Nov99 - Graffiti hack - We changed the name, now we can try to write it - again */ - if ((result = dlp_CreateDB - (socket, pf->info.creator, pf->info.type, - cardno, flags, pf->info.version, - pf->info.name, &db)) < 0) { - return result; - } - } else { - return result; - } - } - - pi_file_get_app_info(pf, &buffer, &l); - - /* Compensate for bug in OS 2.x Memo */ - if (version > 0x0100 - && strcmp(pf->info.name, "MemoDB") == 0 - && l > 0 - && l < 282) { - /* Justification: The appInfo structure was accidentally - lengthend in OS 2.0, but the Memo application does not - check that it is long enough, hence the shorter block - from OS 1.x will cause the 2.0 Memo application to lock - up if the sort preferences are modified. This code - detects the installation of a short app info block on a - 2.0 machine, and lengthens it. This transformation will - never lose information. */ - void *b2 = calloc(1, 282); - memcpy(b2, buffer, (size_t)l); - buffer = b2; - progress.data.db.size.appBlockSize = 282; - l = 282; - freeai = 1; - } - - /* All system updates seen to have the 'ptch' type, so trigger a - reboot on those */ - if (pf->info.creator == pi_mktag('p', 't', 'c', 'h')) - reset = 1; - - if (pf->info.flags & dlpDBFlagReset) - reset = 1; - - /* Upload appInfo block */ - if (l > 0) { - if ((result = dlp_WriteAppBlock(socket, db, buffer, l)) < 0) { - if (freeai) - free(buffer); - goto fail; - } - if (freeai) - free(buffer); - progress.transferred_bytes = l; - if (report_progress && report_progress(socket, - &progress) == PI_TRANSFER_STOP) { - result = pi_set_error(socket, PI_ERR_FILE_ABORTED); - goto fail; - } - } - - /* Upload resources / records */ - if (pf->info.flags & dlpDBFlagResource) { - for (j = 0; j < pf->num_entries; j++) { - int resource_id; - unsigned long type; - - if ((result = pi_file_read_resource(pf, j, &buffer, &size, - &type, &resource_id)) < 0) - goto fail; - - /* Skip empty resource, it cannot be installed */ - if (size == 0) - continue; - - if ((result = dlp_WriteResource(socket, db, type, resource_id, buffer, - size)) < 0) - goto fail; - - progress.transferred_bytes += size; - progress.data.db.transferred_records++; - - if (report_progress && report_progress(socket, - &progress) == PI_TRANSFER_STOP) { - result = pi_set_error(socket, PI_ERR_FILE_ABORTED); - goto fail; - } - - /* If we see a 'boot' section, regardless of file - type, require reset */ - if (type == pi_mktag('b', 'o', 'o', 't')) - reset = 1; - } - } else { - for (j = 0; j < pf->num_entries; j++) { - int attr, - category; - unsigned long resource_id; - - if ((result = pi_file_read_record(pf, j, &buffer, &size, &attr, - &category, &resource_id)) < 0) - goto fail; - - /* Old OS version cannot install deleted records, so - don't even try */ - if ((attr & (dlpRecAttrArchived | dlpRecAttrDeleted)) - && version < 0x0101) - continue; - - if ((result = dlp_WriteRecord(socket, db, attr, resource_id, category, - buffer, size, 0)) < 0) - goto fail; - - progress.transferred_bytes += size; - progress.data.db.transferred_records++; - - if (report_progress - && report_progress(socket, - &progress) == PI_TRANSFER_STOP) { - result = pi_set_error(socket, PI_ERR_FILE_ABORTED); - goto fail; - } - } - } - - if (reset) - dlp_ResetSystem(socket); - - return dlp_CloseDB(socket, db); - -fail: - /* save error codes then restore them after - closing/deleting the DB */ - err1 = pi_error(socket); - err2 = pi_palmos_error(socket); - - LOG((PI_DBG_API, PI_DBG_LVL_ERR, "FILE INSTALL error: pilot-link " - "0x%04x, PalmOS 0x%04x\n", err1, err2)); - if (db != -1 && pi_socket_connected(socket)) - dlp_CloseDB(socket, db); - if (pi_socket_connected(socket)) - dlp_DeleteDB(socket, cardno, pf->info.name); - - pi_set_error(socket, err1); - pi_set_palmos_error(socket, err2); - - if (result >= 0) - result = pi_set_error(socket, PI_ERR_FILE_ERROR); - return result; -} - -int -pi_file_merge(pi_file_t *pf, int socket, int cardno, - progress_func report_progress) -{ - int db = -1, - j, - reset = 0, - version, - result; - void *buffer; - size_t size; - pi_progress_t progress; - - version = pi_version(socket); - - memset(&progress, 0, sizeof(progress)); - progress.type = PI_PROGRESS_SEND_DB; - progress.data.db.pf = pf; - progress.data.db.size.numRecords = pf->num_entries; - progress.data.db.size.dataBytes = pf->app_info_size; - progress.data.db.size.appBlockSize = pf->app_info_size; - progress.data.db.size.maxRecSize = pi_maxrecsize(socket); - - if (dlp_OpenDB(socket, cardno, dlpOpenReadWrite | dlpOpenSecret, - pf->info.name, &db) < 0) - return pi_file_install(pf, socket, cardno, report_progress); - - /* compute total size for progress reporting, and check that - either records are 64k or less, or the handheld can accept - large records. we do this prior to starting the install, - to avoid messing the device up if we have to fail. */ - for (j = 0; j < pf->num_entries; j++) { - result = (pf->info.flags & dlpDBFlagResource) ? - pi_file_read_resource(pf, j, 0, &size, 0, 0) : - pi_file_read_record(pf, j, 0, &size, 0, 0, 0); - if (result < 0) { - LOG((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE INSTALL can't read all records/resources\n")); - goto fail; - } - if (size > 65536 && version < 0x0104) { - LOG((PI_DBG_API, PI_DBG_LVL_ERR, - "FILE INSTALL Database contains" - " record/resource over 64K!\n")); - result = pi_set_error(socket, PI_ERR_DLP_DATASIZE); - goto fail; - } - progress.data.db.size.dataBytes += size; - } - - progress.data.db.size.totalBytes = - progress.data.db.size.dataBytes + - pf->ent_hdr_size * pf->num_entries + - PI_HDR_SIZE + 2; - - /* All system updates seen to have the 'ptch' type, so trigger a - reboot on those */ - if (pf->info.creator == pi_mktag('p', 't', 'c', 'h')) - reset = 1; - - if (pf->info.flags & dlpDBFlagReset) - reset = 1; - - /* Upload resources / records */ - if (pf->info.flags & dlpDBFlagResource) { - for (j = 0; j < pf->num_entries; j++) { - int resource_id; - unsigned long type; - - if ((result = pi_file_read_resource - (pf, j, &buffer, &size, &type, &resource_id)) < 0) - goto fail; - - if (size == 0) - continue; - - if ((result = dlp_WriteResource - (socket, db, type, resource_id, buffer, size)) < 0) - goto fail; - - progress.transferred_bytes += size; - progress.data.db.transferred_records++; - - if (report_progress && report_progress(socket, - &progress) == PI_TRANSFER_STOP) { - result = pi_set_error(socket, PI_ERR_FILE_ABORTED); - goto fail; - } - - /* If we see a 'boot' section, regardless of file - type, require reset */ - if (type == pi_mktag('b', 'o', 'o', 't')) - reset = 1; - } - } else { - for (j = 0; j < pf->num_entries; j++) { - int attr, - category; - unsigned long resource_id; - - if ((result = pi_file_read_record(pf, j, &buffer, &size, - &attr, &category, &resource_id)) < 0) - goto fail; - - /* Old OS version cannot install deleted records, so - don't even try */ - if ((attr & (dlpRecAttrArchived | dlpRecAttrDeleted)) - && version < 0x0101) - continue; - - if ((result = dlp_WriteRecord(socket, db, attr, 0, category, - buffer, size, 0)) < 0) - goto fail; - - progress.transferred_bytes += size; - progress.data.db.transferred_records++; - - if (report_progress && report_progress(socket, - &progress) == PI_TRANSFER_STOP) { - result = PI_ERR_FILE_ABORTED; - goto fail; - } - } - } - - if (reset) - dlp_ResetSystem(socket); - - return dlp_CloseDB(socket, db); - -fail: - if (db != -1 && pi_socket_connected(socket)) { - int err1 = pi_error(socket); - int err2 = pi_palmos_error(socket); - - dlp_CloseDB(socket, db); - - pi_set_error(socket, err1); - pi_set_palmos_error(socket, err2); - } - if (result >= 0) - result = pi_set_error(socket, PI_ERR_FILE_ERROR); - return result; -} -#endif - -/*********************************************************************************/ -/* */ -/* INTERNAL FUNCTIONS */ -/* */ -/*********************************************************************************/ - -/*********************************************************************** - * - * Function: pi_file_close_for_write - * - * Summary: Writes a file to disk - * - * Parameters: None - * - * Returns: Nothing - * - ***********************************************************************/ -static int -pi_file_close_for_write(pi_file_t *pf) -{ - int i, - offset; - FILE *f; - - struct DBInfo *ip; - struct pi_file_entry *entp; - struct stat sbuf; - - unsigned char buf[512]; - unsigned char *p; - - ip = &pf->info; - if (pf->num_entries >= 64 * 1024) { - LOG((PI_DBG_API, PI_DBG_LVL_ERR, - "pi_file_close_for_write: too many entries " - "for this implentation of pi-file: %d\n", - pf->num_entries)); - return PI_ERR_FILE_INVALID; - } - - /* - * Unlink instead of overwriting. - * For the case of something along the lines of: - * cp -lav backup_2005_05_27 backup_2005_05_28 - * Then updating the new copy. - * -- Warp. - */ - - if (!stat (pf->file_name, &sbuf)) - if (S_ISREG(sbuf.st_mode)) - unlink (pf->file_name); - - if ((f = fopen(pf->file_name, "wb")) == NULL) - return PI_ERR_FILE_ERROR; - - ip = &pf->info; - - offset = PI_HDR_SIZE + pf->num_entries * pf->ent_hdr_size + 2; - - p = buf; - memcpy(p, ip->name, 32); - set_short(p + 32, ip->flags); - set_short(p + 34, ip->version); - set_long(p + 36, unix_time_to_pilot_time(ip->createDate)); - set_long(p + 40, unix_time_to_pilot_time(ip->modifyDate)); - set_long(p + 44, unix_time_to_pilot_time(ip->backupDate)); - set_long(p + 48, ip->modnum); - set_long(p + 52, pf->app_info_size ? offset : 0); - offset += pf->app_info_size; - set_long(p + 56, pf->sort_info_size ? offset : 0); - offset += pf->sort_info_size; - set_long(p + 60, ip->type); - set_long(p + 64, ip->creator); - set_long(p + 68, pf->unique_id_seed); - set_long(p + 72, pf->next_record_list_id); - set_short(p + 76, pf->num_entries); - - if (fwrite(buf, PI_HDR_SIZE, 1, f) != 1) - goto bad; - - for (i = 0, entp = pf->entries; i < pf->num_entries; i++, entp++) { - entp->offset = offset; - - p = buf; - if (pf->resource_flag) { - set_long(p, entp->type); - set_short(p + 4, entp->resource_id); - set_long(p + 6, entp->offset); - } else { - set_long(p, entp->offset); - set_byte(p + 4, entp->attrs); - set_treble(p + 5, entp->uid); - } - - if (fwrite(buf, (size_t) pf->ent_hdr_size, 1, f) != 1) - goto bad; - - offset += entp->size; - } - - /* This may just be packing */ - fwrite("\0\0", 1, 2, f); - - if (pf->app_info - && (fwrite(pf->app_info, 1,(size_t) pf->app_info_size, f) != - (size_t) pf->app_info_size)) - goto bad; - - if (pf->sort_info - && (fwrite(pf->sort_info, 1, (size_t) pf->sort_info_size, f) != - (size_t) pf->sort_info_size)) - goto bad; - - - fwrite(pf->tmpbuf->data, pf->tmpbuf->used, 1, f); - fflush(f); - - if (ferror(f) || feof(f)) - goto bad; - - fclose(f); - return 0; - -bad: - fclose(f); - return PI_ERR_FILE_ERROR; -} - -/*********************************************************************** - * - * Function: pi_file_free - * - * Summary: Flush and clean the file handles used - * - * Parameters: file handle pi_file_t* - * - * Returns: void - * - ***********************************************************************/ -static -void pi_file_free(pi_file_t *pf) -{ - ASSERT (pf != NULL); - - if (pf->f != 0) - fclose(pf->f); - - if (pf->app_info != NULL) - free(pf->app_info); - - if (pf->sort_info != NULL) - free(pf->sort_info); - - if (pf->entries != NULL) - free(pf->entries); - - if (pf->file_name != NULL) - free(pf->file_name); - - if (pf->rbuf != NULL) - free(pf->rbuf); - - if (pf->tmpbuf != NULL) - pi_buffer_free(pf->tmpbuf); - - /* in case caller forgets the struct has been freed... */ - memset(pf, 0, sizeof(pi_file_t)); - - free(pf); -} - -/*********************************************************************** - * - * Function: pi_file_set_rbuf_size - * - * Summary: set pi_file rbuf size - * - * Parameters: file handle pi_file_t*, rbuf size - * - * Returns: 0 for success, negative otherwise - * - ***********************************************************************/ -static int -pi_file_set_rbuf_size(pi_file_t *pf, size_t size) -{ - size_t new_size; - void *rbuf; - - if (size > (size_t)pf->rbuf_size) { - if (pf->rbuf_size == 0) { - new_size = size + 2048; - rbuf = malloc(new_size); - } else { - new_size = size + 2048; - rbuf = realloc(pf->rbuf, new_size); - } - - if (rbuf == NULL) - return PI_ERR_GENERIC_MEMORY; - - pf->rbuf_size = new_size; - pf->rbuf = rbuf; - } - - return 0; -} - -/*********************************************************************** - * - * Function: pi_file_append_entry - * - * Summary: Internal function to extend entry list if necessary, - * and return a pointer to the next available slot - * - * Parameters: None - * - * Returns: NULL on allocation error - * - ***********************************************************************/ -static pi_file_entry_t -*pi_file_append_entry(pi_file_t *pf) -{ - int new_count; - size_t new_size; - struct pi_file_entry *new_entries; - struct pi_file_entry *entp; - - if (pf->num_entries >= pf->num_entries_allocated) { - if (pf->num_entries_allocated == 0) - new_count = 100; - else - new_count = pf->num_entries_allocated * 3 / 2; - new_size = new_count * sizeof *pf->entries; - - if (pf->entries == NULL) - new_entries = malloc(new_size); - else - new_entries = realloc(pf->entries, new_size); - - if (new_entries == NULL) - return NULL; - - pf->num_entries_allocated = new_count; - pf->entries = new_entries; - } - - entp = &pf->entries[pf->num_entries++]; - memset(entp, 0, sizeof *entp); - return entp; -} - -static int -pi_file_find_resource_by_type_id(const pi_file_t *pf, - unsigned long restype, int resid, int *resindex) -{ - int i; - struct pi_file_entry *entp; - - if (!pf->resource_flag) - return PI_ERR_FILE_INVALID; - - for (i = 0, entp = pf->entries; i < pf->num_entries; i++, entp++) { - if (entp->type == restype && entp->resource_id == resid) { - if (resindex) - *resindex = i; - return 1; - } - } - return 0; -} - - -/* vi: set ts=8 sw=4 sts=4 noexpandtab: cin */ -/* ex: set tabstop=4 expandtab: */ -/* Local Variables: */ -/* indent-tabs-mode: t */ -/* c-basic-offset: 8 */ -/* End: */ - diff --git a/pilot-link/pi-file.h b/pilot-link/pi-file.h deleted file mode 100644 index 47f7b4105..000000000 --- a/pilot-link/pi-file.h +++ /dev/null @@ -1,435 +0,0 @@ -/* - * $Id: pi-file.h,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * pi-file.h: Pilot File Interface Library - * - * This is free software, licensed under the GNU Library Public License V2. - * See the file COPYING.LIB for details. - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/** @file pi-file.h - * @brief Database file install, retrieve and management interface - * - * The pi-file layer is a convenience management library that provides for - * easy access, creation, install and retrieve of database files (PRC, PDB, - * PQA) - * - * Palm databases on the local machines can be created with pi_file_create() - * or opened read-only using pi_file_open(). Several functions are provided - * to access resources and records. Caller must make sure to use the - * appropriate functions, depending on the type of the database (i.e. only - * use the record read/write functions on data databases, only use the - * resource read/write functions on resource databases). - * - * A set of utility functions are provided to facilitate installing and - * retrieving databases on the devide. pi_file_install() will perform all - * the steps required to install a database on a device. pi_file_merge() can - * be used to update an existing database or add new records/resources to - * it. pi_file_retrieve() will read a database from the device. - */ - -#ifndef _PILOT_FILE_H_ -#define _PILOT_FILE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pi-dlp.h" /* For DBInfo */ - -/** @brief Structure describing a record or resource entry in a database file */ -typedef struct pi_file_entry { - int offset; /**< Offset in the on-disk file */ - int size; /**< Size of the resource or record */ - int resource_id; /**< For resources, resource ID */ - int attrs; /**< Record attributes */ - unsigned long type; /**< For resdources, resource type */ - recordid_t uid; /**< For records, record unique ID */ -} pi_file_entry_t; - -typedef struct pi_file { - int err; - int for_writing; /**< Non-zero if the file was opened with pi_file_create() */ - int app_info_size; /**< Size of the appInfo block */ - int sort_info_size; /**< Size of the sortInfo block */ - int next_record_list_id; - int resource_flag; - int ent_hdr_size; /**< Size of the header for each resource/record (depends on whether the file is a resource or record file) */ - int num_entries; /**< Number of actual entries in the entries memory block */ - int num_entries_allocated; /**< Number of entries allocated in the entries memory block */ - int rbuf_size; /**< Size of the internal read buffer */ - FILE *f; /**< Actual on-disk file */ - pi_buffer_t *tmpbuf; /**< Temporary buffer for databases opened with pi_file_create() */ - char *file_name; /**< Access path */ - void *app_info; /**< Pointer to the appInfo block or NULL */ - void *sort_info; /**< Pointer to the sortInfo block or NULL */ - void *rbuf; /**< Read buffer, used internally */ - unsigned long unique_id_seed; /**< Database file's unique ID seed as read from an existing file */ - struct DBInfo info; /**< Database information and attributes */ - struct pi_file_entry *entries; /**< Array of records / resources */ -} pi_file_t; - -/** @brief Transfer progress callback structure - * - * The progress callback structure is prepared by the client application and - * passed to pi_file_install(), pi_file_merge() and pi_file_retrieve() - * functions. It allows the client application to be notified during a file - * transfer (i.e. to update a progress indicator) and gives it a chance to - * cancel transfers. - */ -typedef struct { - int type; /**< Transfer type (see #piProgressType enum) */ - int transferred_bytes; /**< Current transferred bytes */ - void *userinfo; /**< Provided by and passed back to client (not used for now, will be in a future release) */ - union { - struct { - pi_file_t *pf; /**< May be NULL */ - struct DBSizeInfo size; /**< Size information */ - int transferred_records;/**< Number of records or resources */ - } db; - - struct { - char *path; /**< VFS file path */ - long total_bytes; /**< File size in bytes */ - } vfs; - } data; -} pi_progress_t; - -/** @brief Progress callback function definition - * - * Callback should return either #PI_TRANSFER_STOP or - * #PI_TRANSFER_CONTINUE - */ -typedef int (*progress_func)(int socket, pi_progress_t *progress); - -/** @brief Transfer progress types for the @a type member of pi_progress_t */ -enum piProgressType { - PI_PROGRESS_SEND_DB = 1, /**< Sending a database */ - PI_PROGRESS_RECEIVE_DB, /**< Receiving a database */ - PI_PROGRESS_SEND_VFS, /**< Sending a VFS file */ - PI_PROGRESS_RECEIVE_VFS /**< Receiving a VFS file */ -}; - - -#define PI_TRANSFER_STOP 0 /**< Returned by progress callback to stop the transfer */ -#define PI_TRANSFER_CONTINUE 1 /**< Returned by progress callback to continue the transfer */ - -/** @name Opening and closing files */ -/*@{*/ - /** @brief Open a database for read-only access - * - * Don't dispose of the returned structure directly. - * Use pi_file_close() instead. - * - * @param name The access path to the database to open on the local machine - * @return An initialized pi_file_t structure or NULL. - */ - extern pi_file_t *pi_file_open - PI_ARGS((const char *name)); - - /** @brief Create a new database file - * - * A new database file is created on the local machine. - * - * @param name Access path of the new file to create - * @param INPUT Characteristics of the database to create - * @return A new pi_file_t structure. Use pi_file_close() to write data and close file. - */ - extern pi_file_t *pi_file_create - PI_ARGS((const char *name, const struct DBInfo *INPUT)); - - /** @brief Closes a local file - * - * If the file had been opened with pi_file_create, all - * modifications are written to disk before the file is closed - * - * @param pf The pi_file_t structure is being disposed of by this function - * @return An error code (see file pi-error.h) - */ - extern int pi_file_close PI_ARGS((pi_file_t *pf)); -/*@}*/ - -/** @name Reading from open files */ -/*@{*/ - /** @brief Returns database specification - * - * @param pf An open file - * @return DBInfo structure describing the file - */ - extern void pi_file_get_info - PI_ARGS((const pi_file_t *pf, struct DBInfo *OUTPUT)); - - /** @brief Returns the file's appInfo block - * - * The returned data is not a copy of the pi_file_t's appInfo - * structures. Don't dispose or modify it. - * - * @param pf An open file - * @param datap On return, ptr to appInfo data or NULL - * @param sizep On return, size of the appInfoBlock - */ - extern void pi_file_get_app_info - PI_ARGS((pi_file_t *pf, void **datap, size_t *sizep)); - - /** @brief Returns the file's sortInfo block - * - * The returned data is not a copy of the pi_file_t's sortInfo - * block: do not dispose of it! - * - * @param pf An open file - * @param datap On return, ptr to sortInfo data or NULL - * @param sizep On return, size of the sortInfoBlock - */ - extern void pi_file_get_sort_info - PI_ARGS((pi_file_t *pf, void **dadtap, size_t *sizep)); - - /** @brief Read a resource by index - * - * If it exists, the returned data points directly into the file - * structures. Don't dispose or modify it. - * - * @param pf An open file - * @param resindex The resource index - * @param bufp On return, pointer to the resource data block - * @param sizep If not NULL, size of the resource data - * @param restype If not NULL, resource type - * @param resid If not NULL, resource - * @return Negative error code on error - */ - extern int pi_file_read_resource - PI_ARGS((pi_file_t *pf, int resindex, void **bufp, size_t *sizep, - unsigned long *restype, int *resid)); - - /** @brief Read a resource by type and ID - * - * If it exists, the returned data points directly into the file - * structures. - * - * @param pf An open file - * @param restype Resource type - * @param resid Resource ID - * @param bufp On return, pointer to the resource data or NULL - * @param sizep If not NULL, the size of the resource data - * @param resindex If not NULL, on return contains the resource index - * @return Negative error code on error - */ - extern int pi_file_read_resource_by_type_id - PI_ARGS((pi_file_t *pf, unsigned long restype, int resid, - void **bufp, size_t *sizep, int *resindex)); - - /** @brief Checks whether a resource type/id exists in an open file - * - * @param pf An open file - * @param restype Resource type to check - * @param resid Resource ID to check - * @return Non-zero if a resource with same type and id exists - */ - extern int pi_file_type_id_used - PI_ARGS((const pi_file_t *pf, unsigned long restype, int resid)); - - /** @brief Checks whether a record with the given UID exists - * - * @param pf An open file - * @param uid The record UID to look for - * @return Non-zero if a record with the same UID exists - */ - extern int pi_file_id_used - PI_ARGS((const pi_file_t *pf, recordid_t uid)); - - /** @brief Read a record by index - * - * If it exists, the returned data points directly into the file - * structures. Don't dispose or modify it. - * - * @param pf An open file - * @param recindex Record index - * @param bufp On return, pointer to the resource data or NULL - * @param sizep If not NULL, the size of the resource data - * @param recattrs If not NULL, the record attributes - * @param category If not NULL, the record category - * @param recuid If not NULL, the record unique ID - * @return Negative error code on error - */ - extern int pi_file_read_record - PI_ARGS((pi_file_t *pf, int recindex, void **bufp, size_t *sizep, - int *recattrs, int *category, recordid_t *recuid)); - - /** @brief Read a record by unique ID - * - * If it exists, the returned data points directly into the file - * structures. Don't dispose or modify it. - * - * @param pf An open file - * @param recuid The record unique ID - * @param bufp On return, pointer to the resource data or NULL - * @param sizep If not NULL, the size of the resource data - * @param recindex If not NULL, the record index - * @param recattrs If not NULL, the record attributes - * @param category If not NULL, the record category - * @return Negative error code on error - */ - extern int pi_file_read_record_by_id - PI_ARGS((pi_file_t *pf, recordid_t recuid, void **bufp, - size_t *sizep, int *recindex, int *recattrs, int *category)); - -#ifndef SWIG - extern void pi_file_get_entries - PI_ARGS((pi_file_t *pf, int *entries)); -#endif -/*@}*/ - -/** @name Modifying files open for write */ -/*@{*/ - /* may call these any time before close (even multiple times) */ - extern int pi_file_set_info - PI_ARGS((pi_file_t *pf, const struct DBInfo *infop)); - - /** @brief Set the database's appInfo block - * - * The file takes ownership of the passed data block - * - * @param pf A file open for write - * @param data Pointer to the data or NULL to clear the appInfo block - * @param size Size of the new data block - * @return Negative code on error - */ - extern int pi_file_set_app_info - PI_ARGS((pi_file_t *pf, void *data, size_t size)); - - /** @brief Set the database's sortInfo block - * - * The file takes ownership of the passed data block - * - * @param pf A file open for write - * @param data Pointer to the data or NULL to clear the sortInfo block - * @param size Size of the new data block - * @return Negative code on error - */ - extern int pi_file_set_sort_info - PI_ARGS((pi_file_t *pf, void *data, size_t size)); - - /** @brief Add a resource to a file open for write - * - * The file takes ownership of the passed data block - * Function will return PI_ERR_FILE_ALREADY_EXISTS if resource with - * same type/id already exists - * - * @param pf A file open for write - * @param data The resource data - * @param size The resource size - * @param restype Resource type - * @param resid Resource ID - * @return Negative code on error. - */ - extern int pi_file_append_resource - PI_ARGS((pi_file_t *pf, void *data, size_t size, - unsigned long restype, int resid)); - - /** @brief Add a record to a file open for write - * - * The file takes ownership of the passed data block Function will - * return PI_ERR_FILE_ALREADY_EXISTS if record with same unique ID - * already exists in the database - * - * @param pf A file open for write - * @param data The resource data - * @param size The resource size - * @param recattrs Record attributes - * @param category Record category - * @param recuid Record unique ID (pass 0 to have recuid automatically allocated) - * @return Negative code on error. - */ - extern int pi_file_append_record - PI_ARGS((pi_file_t *pf, void *buf, size_t size, int recattrs, - int category, recordid_t recuid)); -/*@}*/ - -/** @name File transfer utilities */ -/*@{*/ - /** @brief Retrieve a file from the handheld - * - * You must first create the local file using pi_file_create() - * - * @param pf A file open for write - * @param socket Socket to the connected handheld - * @param cardno Card number the file resides on (usually 0) - * @param report_progress Progress function callback or NULL (see #pi_progress_t structure) - * @return Negative code on error - */ - extern int pi_file_retrieve - PI_ARGS((pi_file_t *pf, int socket, int cardno, - progress_func report_progress)); - - /** @brief Install a new file on the handheld - * - * You must first open the local file with pi_file_open() - * - * @param pf An open file - * @param socket Socket to the connected handheld - * @param cardno Card number to install to (usually 0) - * @param report_progress Progress function callback or NULL (see #pi_progress_t structure) - * @return Negative code on error - */ - extern int pi_file_install - PI_ARGS((pi_file_t *pf, int socket, int cardno, - progress_func report_progress)); - - /** @brief Install a new file on the handheld or merge with an existing file - * - * The difference between this function and pi_file_install() is - * that if the file already exists on the handheld, pi_file_merge() - * will append data to the existing file. For resource files, all - * resources from the local file are sent to the handheld. If - * resources with the same type/ID exist in the handheld file, they - * are replaced with the new one. - * - * You must first open the local file with pi_file_open() - * - * @param pf An open file - * @param socket Socket to the connected handheld - * @param cardno Card number to install to (usually 0) - * @param report_progress Progress function callback or NULL (see #pi_progress_t structure) - * @return Negative code on error - */ - extern int pi_file_merge - PI_ARGS((pi_file_t *pf, int socket, int cardno, - progress_func report_progress)); -/*@}*/ - -/** @name Time utilities */ -/*@{*/ - /** @brief Convert Unix time to Palm OS time - * - * @param t Unix time value - * @return Time value with Palm OS timebase - */ - extern unsigned long unix_time_to_pilot_time - PI_ARGS((time_t t)); - - /** @brief Convert Palm OS time to Unix time - * - * @param raw_time Time value expressed in Palm OS timebase (seconds from 01-JAN-1904, 00:00) - * @return Unix time - */ - extern time_t pilot_time_to_unix_time - PI_ARGS((unsigned long raw_time)); -/*@}*/ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/pilot-link/pi-macros.h b/pilot-link/pi-macros.h deleted file mode 100644 index ca1deb890..000000000 --- a/pilot-link/pi-macros.h +++ /dev/null @@ -1,290 +0,0 @@ -/* - * $Id: pi-macros.h,v 1.1 2007/07/21 03:54:52 robertl Exp $ - * - * pi-macros.h: pilot-link specific macro defintions - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Library General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - * General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef _PILOT_MACROS_H_ -#define _PILOT_MACROS_H_ - -#include -#include "pi-args.h" - -typedef unsigned long recordid_t; - -#ifdef __cplusplus -extern "C" { -#endif - - extern double get_float PI_ARGS((void *)); - extern void set_float PI_ARGS((void *, double)); - extern int compareTm PI_ARGS((struct tm * a, struct tm * b)); - -#ifdef __cplusplus -} -#endif -#ifndef __cplusplus -#define get_long(ptr) \ - (unsigned long) ( \ - (((unsigned long)((unsigned char *)(ptr))[0]) << 24) | \ - (((unsigned long)((unsigned char *)(ptr))[1]) << 16) | \ - (((unsigned long)((unsigned char *)(ptr))[2]) << 8) | \ - (((unsigned long)((unsigned char *)(ptr))[3]) ) ) - - -#define get_treble(ptr) ((unsigned long)\ - ((((unsigned char*)(ptr))[0] << 16) | \ - (((unsigned char*)(ptr))[1] << 8) | \ - (((unsigned char*)(ptr))[2]))) -#define get_short(ptr) ((unsigned short)\ - ((((unsigned char*)(ptr))[0] << 8) | \ - (((unsigned char*)(ptr))[1]))) -#define get_byte(ptr) (((unsigned char*)(ptr))[0]) -#define get_slong(ptr) (signed long)(\ - (get_long((ptr)) > 0x7FFFFFFF) ?\ - (((signed long)(get_long((ptr)) & 0x7FFFFFFF)) - 0x80000000):\ - ((signed long)(get_long((ptr))))\ - ) -#define get_streble(ptr) (signed long)(\ - (get_treble((ptr)) > 0x7FFFFF) ?\ - (((signed long)(get_treble((ptr)) & 0x7FFFFF)) - 0x800000):\ - ((signed long)(get_treble((ptr))))\ - ) -#define get_sshort(ptr) (signed short)(\ - (get_short((ptr)) > 0x7FFF) ?\ - (((signed short)(get_short((ptr)) & 0x7FFF)) - 0x8000):\ - ((signed short)(get_short((ptr))))\ - ) -#define get_sbyte(ptr) (signed char)(\ - (get_byte((ptr)) > 0x7F) ?\ - (((signed char)(get_byte((ptr)) & 0x7F)) - 0x80):\ - ((signed char)(get_byte((ptr))))\ - ) -#define set_long(ptr,val) ((((unsigned char*)(ptr))[0] = (unsigned char)(((unsigned long)(val)) >> 24) & 0xff), \ - (((unsigned char*)(ptr))[1] = (((unsigned long)(val)) >> 16) & 0xff), \ - (((unsigned char*)(ptr))[2] = (((unsigned long)(val)) >> 8) & 0xff), \ - (((unsigned char*)(ptr))[3] = (((unsigned long)(val)) >> 0) & 0xff)) -#define set_slong(ptr,val) set_long((ptr),((unsigned long)(\ - (((signed long)(val)) < 0) ?\ - ((unsigned long)(((signed long)(val)) + 0x80000000) | 0x80000000) :\ - (val)\ - ))) -#define set_treble(ptr,val) ((((unsigned char*)(ptr))[0] = (unsigned char)(((unsigned long)(val)) >> 16) & 0xff), \ - (((unsigned char*)(ptr))[1] = (((unsigned long)(val)) >> 8) & 0xff), \ - (((unsigned char*)(ptr))[2] = (((unsigned long)(val)) >> 0) & 0xff)) -#define set_streble(ptr,val) set_treble((ptr),((unsigned long)(\ - (((signed long)(val)) < 0) ?\ - ((unsigned long)(((signed long)(val)) + 0x800000) | 0x800000) :\ - (val)\ - ))) -#define set_short(ptr,val) ((((unsigned char*)(ptr))[0] = (((unsigned short)(val)) >> 8) & 0xff), \ - (((unsigned char*)(ptr))[1] = (((unsigned short)(val)) >> 0) & 0xff)) -#define set_sshort(ptr,val) set_short((ptr),((unsigned short)(\ - (((signed short)(val)) < 0) ?\ - ((unsigned short)(((signed short)(val)) + 0x8000) | 0x8000) :\ - (val)\ - ))) -#define set_byte(ptr,val) (((unsigned char*)(ptr))[0]=(val)) -#define set_sbyte(ptr,val) set_byte((ptr),((unsigned char)(\ - (((signed char)(val)) < 0) ?\ - ((unsigned char)(((signed char)(val)) + 0x80) | 0x80) :\ - (val)\ - ))) -#define char4(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4)) -#else /*ifdef __cplusplus */ -inline unsigned long get_long(const void *buf) -{ - unsigned char *ptr = (unsigned char *) buf; - - return (*ptr << 24) | (*(++ptr) << 16) | (*(++ptr) << 8) | - *(++ptr); -} - -inline signed long get_slong(const void *buf) -{ - unsigned long val = get_long(buf); - - if (val > 0x7FFFFFFF) - return ((signed long) (val & 0x7FFFFFFF)) - 0x80000000; - else - return val; -} - -inline unsigned long get_treble(const void *buf) -{ - unsigned char *ptr = (unsigned char *) buf; - - return (*ptr << 16) | (*(++ptr) << 8) | *(++ptr); -} - -inline signed long get_streble(const void *buf) -{ - unsigned long val = get_treble(buf); - - if (val > 0x7FFFFF) - return ((signed long) (val & 0x7FFFFF)) - 0x800000; - else - return val; -} - -inline int get_short(const void *buf) -{ - unsigned char *ptr = (unsigned char *) buf; - - return (*ptr << 8) | *(++ptr); -} - -inline signed short get_sshort(const void *buf) -{ - unsigned short val = get_short(buf); - - if (val > 0x7FFF) - return ((signed short) (val & 0x7FFF)) - 0x8000; - else - return val; -} - -inline int get_byte(const void *buf) -{ - return *((unsigned char *) buf); -} - -inline signed char get_sbyte(const void *buf) -{ - unsigned char val = get_byte(buf); - - if (val > 0x7F) - return ((signed char) (val & 0x7F)) - 0x80; - else - return val; -} - -inline void set_long(void *buf, const unsigned long val) -{ - unsigned char *ptr = (unsigned char *) buf; - - *ptr = (unsigned char) ((val >> 24) & 0xff); - *(++ptr) = (unsigned char) ((val >> 16) & 0xff); - *(++ptr) = (unsigned char) ((val >> 8) & 0xff); - *(++ptr) = (unsigned char) (val & 0xff); -} - -inline void set_slong(void *buf, const signed long val) -{ - unsigned long uval; - - if (val < 0) { - uval = (val + 0x80000000); - uval |= 0x80000000; - } else - uval = val; - set_long(buf, uval); -} - -inline void set_treble(void *buf, const unsigned long val) -{ - unsigned char *ptr = (unsigned char *) buf; - - *ptr = (unsigned char) ((val >> 16) & 0xff); - *(++ptr) = (unsigned char) ((val >> 8) & 0xff); - *(++ptr) = (unsigned char) (val & 0xff); -} - -inline void set_streble(void *buf, const signed long val) -{ - unsigned long uval; - - if (val < 0) { - uval = (val + 0x800000); - uval |= 0x800000; - } else - uval = val; - set_treble(buf, uval); -} - -inline void set_short(void *buf, const int val) -{ - unsigned char *ptr = (unsigned char *) buf; - - *ptr = (val >> 8) & 0xff; - *(++ptr) = val & 0xff; -} - -inline void set_sshort(void *buf, const signed short val) -{ - unsigned short uval; - - if (val < 0) { - uval = (val + 0x8000); - uval |= 0x8000; - } else - uval = val; - set_treble(buf, uval); -} - -inline void set_byte(void *buf, const int val) -{ - *((unsigned char *) buf) = val; -} - -inline void set_sbyte(void *buf, const signed char val) -{ - unsigned char uval; - - if (val < 0) { - uval = (val + 0x80); - uval |= 0x80; - } else - uval = val; - set_byte(buf, uval); -} - -inline struct tm *getBufTm(struct tm *t, const void *buf, int setTime) -{ - unsigned short int d = get_short(buf); - - t->tm_year = (d >> 9) + 4; - t->tm_mon = ((d >> 5) & 15) - 1; - t->tm_mday = d & 31; - - if (setTime) { - t->tm_hour = 0; - t->tm_min = 0; - t->tm_sec = 0; - } - - t->tm_isdst = -1; - - mktime(t); - - return t; -} - -inline void setBufTm(void *buf, const struct tm *t) -{ - set_short(buf, - ((t->tm_year - 4) << 9) | ((t->tm_mon + - 1) << 5) | t->tm_mday); -} - -inline unsigned long char4(char c1, char c2, char c3, char c4) -{ - return (c1 << 24) | (c2 << 16) | (c3 << 8) | c4; -} - -#endif /*__cplusplus*/ -#endif /* _PILOT_MACROS_H_ */ diff --git a/pilot-link/pi-source.h b/pilot-link/pi-source.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/quovadis.c b/quovadis.c index 745c151ec..007dbb67f 100644 --- a/quovadis.c +++ b/quovadis.c @@ -22,16 +22,12 @@ #include "quovadis.h" #if PDBFMTS_ENABLED -static FILE *file_in; -static FILE *file_out; -static const char *out_fname; -static struct pdb *opdb; +static pdbfile *file_in, *file_out; -static int ct; -static ubyte* rec_ptr = NULL; -static ubyte* current_rec = NULL; +static gbuint8* rec_ptr = NULL; +static gbuint8* current_rec = NULL; static int rec_index = 0; - +static int ct; static char *dbname = NULL; static @@ -77,13 +73,13 @@ static int wpt_to_icon(geocache_type type) { static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = pdb_open(fname, MYNAME); } static void rd_deinit(void) { - fclose(file_in); + pdb_close(file_in); if ( dbname ) { xfree(dbname); dbname = NULL; @@ -93,14 +89,14 @@ rd_deinit(void) static void wr_init(const char *fname) { - file_out = xfopen(fname, "wb", MYNAME); - out_fname = fname; + file_out = pdb_create(fname, MYNAME); + ct = 0; } static void wr_deinit(void) { - fclose(file_out); + pdb_close(file_out); if ( dbname ) { xfree(dbname); dbname = NULL; @@ -111,21 +107,16 @@ static void data_read(void) { struct record *rec; - struct pdb *pdb; - struct pdb_record *pdb_rec; + pdbrec_t *pdb_rec; int i; - if (NULL == (pdb = pdb_Read(fileno(file_in)))) { - fatal(MYNAME ": pdb_Read failed\n"); - } - - if ((pdb->creator != MYCREATOR) || (pdb->type != MYTYPE)) { + if ((file_in->creator != MYCREATOR) || (file_in->type != MYTYPE)) { fatal(MYNAME ": Not a QuoVadis file.\n"); } /* Ignore the first record, it contains one zero byte */ - for(pdb_rec = pdb->rec_index.rec->next; pdb_rec; pdb_rec=pdb_rec->next) { - int num_recs = pdb_rec->data_len / sizeof(struct record); + for(pdb_rec = file_in->rec_list->next; pdb_rec; pdb_rec = pdb_rec->next) { + int num_recs = pdb_rec->size / sizeof(struct record); for (i = 0; i < num_recs; i++) { waypoint *wpt_tmp; @@ -146,7 +137,6 @@ data_read(void) waypt_add(wpt_tmp); } } - free_pdb(pdb); } @@ -157,17 +147,11 @@ quovadis_writewpt(waypoint *wpt) int i; if (current_rec == NULL) { - ubyte dummy = 0; - struct pdb_record *pdb_rec; - pdb_rec = new_Record(0, 0, ct++, 1, &dummy); - if (pdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } - if (pdb_AppendRecord(opdb, pdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } + gbuint8 dummy = 0; + + pdb_write_rec(file_out, 0, 0, ct++, &dummy, 1); - current_rec = (ubyte *) xcalloc(MAXCHUNKSIZE, 1); + current_rec = (gbuint8 *) xcalloc(MAXCHUNKSIZE, 1); rec_index = 0; rec_ptr = current_rec; } @@ -227,22 +211,18 @@ data_write(void) extern queue waypt_head; waypoint *waypointp; - if (NULL == (opdb = new_pdb())) { - fatal (MYNAME ": new_pdb failed\n"); - } - if ( dbname ) { - strncpy( opdb->name, dbname, PDB_DBNAMELEN ); + strncpy( file_out->name, dbname, PDB_DBNAMELEN ); } else { - strncpy(opdb->name, "QuoVadisMarkerDB", PDB_DBNAMELEN); + strncpy(file_out->name, "QuoVadisMarkerDB", PDB_DBNAMELEN); } - opdb->name[PDB_DBNAMELEN-1] = 0; - opdb->attributes = PDB_ATTR_BACKUP; - opdb->ctime = opdb->mtime = current_time() + 2082844800U; - opdb->type = MYTYPE; /* CWpt */ - opdb->creator = MYCREATOR; /* cGPS */ - opdb->version = 1; + file_out->name[PDB_DBNAMELEN-1] = 0; + file_out->attr = PDB_FLAG_BACKUP; + file_out->ctime = file_out->mtime = current_time() + 2082844800U; + file_out->type = MYTYPE; /* CWpt */ + file_out->creator = MYCREATOR; /* cGPS */ + file_out->version = 1; /* * All this is to sort by waypoint names before going to QuoVadis. @@ -265,21 +245,10 @@ data_write(void) } if (rec_index != 0) { - struct pdb_record* pdb_rec; - pdb_rec = new_Record(0, 0, ct++, (uword) (rec_index * - sizeof(struct record)), current_rec); - - if (pdb_rec == NULL) { - fatal(MYNAME ": libpdb couldn't create record\n"); - } - - if (pdb_AppendRecord(opdb, pdb_rec)) { - fatal(MYNAME ": libpdb couldn't append record\n"); - } + pdb_write_rec(file_out, 0, 0, ct++, current_rec, rec_index * sizeof(struct record)); } xfree(current_rec); - pdb_Write(opdb, fileno(file_out)); xfree(htable); } diff --git a/quovadis.h b/quovadis.h index 19f7c88c1..fe8a8d030 100644 --- a/quovadis.h +++ b/quovadis.h @@ -22,8 +22,7 @@ #define __quovadis_h__ #include "defs.h" -#include "coldsync/palm.h" -#include "coldsync/pdb.h" +#include "pdbfile.h" #define MYNAME "QuoVadis" #define MYTYPE 0x51564D52 /* QVMR */ -- 2.30.2